iOS Programmatically display a view controller based on current user

末鹿安然 提交于 2019-12-25 05:33:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!