我有一个 UIViewController,在该 View Controller 内我想在不使用 Interface Builder 的情况下调用 CustomUIViewController。我一直在使用这个,它可以工作,但它需要 Storyboard ID。
UIStoryboard *storyboard = self.storyboard;
UIViewController *myVC = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"PageID"];
[self presentModalViewController:myVC animated:YES];
是否有一种方法可以在不使用 Segues 和 IB 的情况下从 UIViewController 转到 customViewController?
最佳答案
使用这个:
UIViewController *myVc = [[UIViewController alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
这显然会呈现一个新的空白 View Controller ,如果您想要 PageID View ,则将 UIViewController
替换为 PageID
类的名称(即 . h/.m 文件名)
所以我假设是这样的:
PageID *myVc = [[PageID alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
如果你想在导航 Controller 中使用它:
PageID *myVc = [[PageID alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myVc];
[self presentViewController: navController animated:YES completion:nil];
或者,如果您不希望它是模态的(不需要创建新的导航 Controller ,因为它将添加到现有的导航 Controller 堆栈中,即 [self navigationController]
:
[[self navigationController] pushViewController:myVc animated:YES];
关于ios - 没有 IB 的 Xcode UIViewController 到 customUIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24575529/