ios - 没有 IB 的 Xcode UIViewController 到 customUIViewController

标签 ios uiviewcontroller uistoryboard

我有一个 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/

相关文章:

ios - 强制WKWebView显示移动版本

ios - 在 Swift 中禁用没有 UserInteractionEnabled 的单元格选择

iphone - MPMoviePlayerController 慢速前进和后退运动

ios - 将 viewController View 添加到 UIScrollView

ios - 是否可以更改所有 View Controller 的状态栏颜色?

ios - Storyboard线程错误

ios - 如何在 iOS 中使用导航栏隐藏/显示 View 的标签栏?

iphone - 如何使用 subview Controller 模式链接嵌套 View Controller

ios - 如何在ios中选择ipad应用程序?

ios - 如何关闭 Storyboard 弹出框