问题
I have a PreferencesViewController that shows information about current user:
 
But it depends on the current user. If the user hasn't logged in yet, I am triggering a segue to LoginViewController on PreferencesViewController viewWillAppear method:
 
The problem comes when the user hasn't signed in and taps again on the Preferences tab. It unwinds the segue back to PreferencesViewController, causing unexpected behaviour (PreferencesViewController should only be rendered when the user has logged in)
What is the best way to solve this? The approach I am using is okay? Can it be more optimal?
回答1:
You should implement the delegate method, tabBarController:shouldSelectViewController:, and return NO if the user hasn't signed in.
来源:https://stackoverflow.com/questions/20485491/ios-programmatically-display-a-view-controller-based-on-current-user