我有一个 UIViewController
,它有一个按钮,我在 StoryBoard
中创建了两个 View Controller ,并将其连接到 Cocoa 类。我想根据某些条件将 UIViewController
更改为两个 View Controller 之一。
我试过:
// 1
BOOL isLoggedIn=TRUE;
NSString *storyboardId = isLoggedIn ? @"FirstViewController" : @"SecondViewController";
self.view = [self.view.inputViewController.storyboard instantiateViewControllerWithIdentifier:storyboardId];
// 2
[self.view addSubview:FirstViewController];
感谢您的及时回复
最佳答案
从 Main.storyboard
中选择您的 subview Controller ,然后从右侧菜单中的身份检查器中将 StoryBoardID
更改为 someID
然后,将此代码添加到按钮操作方法中:
ViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"someID"];
[self presentViewController:NVC animated:YES completion:nil];
关于ios - 以编程方式更改 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31630213/