Showing a different XIB/NIB in an iOS app

落花浮王杯 提交于 2019-12-01 14:19:41

The way I handle switching between actual xib's, and I'm sure there are a multitude of ways to accomplish the same thing, is to have my App Delegate act as a routing center between my views.

I subscribe my App Delegate to recieve events from button presses for existing views. When it recieves a request to switch views, such as a button press, I do something like this:

- (void) showLogin
{  
    LoginViewController *loginViewController = [[LoginViewController alloc]
                                                   initWithNibName:@"LoginViewController" bundle:nil];

    // Show
    self.loginViewController = loginViewController;
    [loginViewController release];

    self.window.rootViewController = self.loginViewController;
}

I set my rootViewController to the view I am attempting to display. It doesn't release the old controller, but simply replaces the view being displayed. You can place more logic in to determine if it's already displayed, close out other views, etc. In most simplistic terms, this works for me.

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