Getting iPhone app to display one of two different views

喜欢而已 提交于 2019-12-25 01:50:00

问题


I have a program where we are using a navigation controller and need the app to launch to one of two different views. Basically if certain info has previously been entered then we need the app to launch to view A, but if the info has never been entered then we need it to launch to view B. I am having difficulty getting this to work and am wondering what ways if any I could implement this. I am certain it needs to be done in the app delegate but I am not sure how. Thanks in advance!


回答1:


Implement the following method in your app delegate.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    [window makeKeyAndVisible];
    if(condition) {
        [window addSubview:[mainViewControllerA view]];
    } else {
        [window addSubview:[mainViewControllerB view]];
    }
}

There you can choose which view to load depending on your condition.




回答2:


From your question, it sounds as though your UINavigationController is defined inside a XIB along with your root view controller. In that case, you will need to load the appropriate view from within application:didFinishLaunchingWithOptions: of your App Delegate. From there, you can set the first view controller for the UINavigationController using setViewControllers:animated:.




回答3:


I have met this issue and solved it.

In you navigation controller build a container view.

Then depending on your conditions you decided what view to put in the container. You might have built these two views beforehand. Then, you can add the view into the container view. I think the "Elements" sample has an example of the container view.



来源:https://stackoverflow.com/questions/3330962/getting-iphone-app-to-display-one-of-two-different-views

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