Redirect to another view controller

纵饮孤独 提交于 2019-12-08 09:12:00

问题


I am developing an iOS app for iPhone and iPad. I have two storyboard files, called: Main_iPhone and Main_iPad. I have made a loginscreen in these storyboards and I have set up a LoginViewController. After a succesfull login, I want to redirect the user to another screen in Main_iPhone or Main_iPad. I gave this screen the name Dashboard and in the Identity Inspector the custom class DashboardViewController. I have created this file.

I'm developing for iOS 7 in Xcode 5

How can I redirect the user to my dashboard?


回答1:


There is a few way you can do it. First is create DashboardViewController and present it to view hierarchy:

DashboardViewController *vc = [[DashboardViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];

Another one is create segue in storyboard from Login to Dashboard and when you want to redirect just call:

[self performSegueWithIdentifier:@"SEGUE_IDENTIFIRE" sender:nil];

SEGUE_IDENTIFIRE is a segue name you need to set up in storyboard.




回答2:


For the purpose, when you complete the login you can switch through storyboards by instantiating a UIStoryboard object and presenting new UIViewController that must be instantiated with method of UIStoryboad object, below an example:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
                            @"myOtherStoryboard" bundle:nil];
[self presentViewController:[storyboard instantiateViewControllerWithIdentifier:
                                  @"myViewOfOtherStoryaboard"] animated:NO completion:nil];

Hope this help.




回答3:


Sometimes, users end up reaching this if they only search for "redirect to another view controller". So here is a solution that I would be looking for...

Swift 3 solution

let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "yourViewControllerID")
present(controller, animated: true, completion: nil)


来源:https://stackoverflow.com/questions/23632784/redirect-to-another-view-controller

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