重定向到另一个视图控制器

时间:2014-05-13 13:35:52

标签: ios objective-c uiviewcontroller storyboard

我正在开发适用于iPhone和iPad的iOS应用。我有两个故事板文件,名为:Main_iPhone和Main_iPad。我在这些故事板中制作了一个登录屏幕,并设置了一个LoginViewController。成功登录后,我想将用户重定向到Main_iPhone或Main_iPad中的另一个屏幕。我给这个屏幕命名为Dashboard,并在Identity Inspector中为自定义类DashboardViewController。我创建了这个文件。

我正在为Xcode 5中的iOS 7开发

如何将用户重定向到我的信息中心?

3 个答案:

答案 0 :(得分:3)

有几种方法可以做到。 首先是创建DashboardViewController并将其呈现给视图层次结构:

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

另一个是在从登录到仪表板的故事板中创建segue,当你想重定向时,只需要调用:

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

SEGUE_IDENTIFIRE是您需要在故事板中设置的segue名称。

答案 1 :(得分:1)

为此,当您完成登录时,您可以通过实例化UIStoryboard对象并呈现必须使用UIStoryboad对象的方法实例化的新UIViewController来切换故事板,如下所示:

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

希望得到这个帮助。

答案 2 :(得分:1)

有时,如果用户只搜索"重定向到另一个视图控制器",则最终会达到此目的。所以这是我要寻找的解决方案......

Swift 3 解决方案

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