How can I manually switch between UIViewControllers in storyboard?

后端 未结 4 2296
你的背包
你的背包 2020-12-01 03:00

All I need is to view a UIView controller in same storyboard file manually with code. I use storyboard to make all forms and connections. My application starts

4条回答
  •  眼角桃花
    2020-12-01 03:31

    I'm guessing that you are using a UINavigationController. Then you can simply do like this:

    LoginViewController *controller = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];
    

    Update:

    If you are using a UIStoryboard, you can set the identifier of your new viewcontroller, and then push it onto your navigationController. To set the identifier, choose your view, open the Attributes Inspector, and set the identifier ("LoginIdentifier" in my example). Then you can do this:

    LoginViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginIdentifier"];
    [self.navigationController pushViewController:controller animated:YES];
    

    As a sidenote, I see that you are using capital characters for your methods. You should probably try to avoid that, and instead use lowered first-characters in your method names. And since you say you are learning Objective-C, you should check out this awesome thread here on SO: link.

    Update 2:

    Here is a zip file with a project showing how to do this. :-)

提交回复
热议问题