繁体   English   中英

如何将视图控制器指定为UINavigationController在自定义类中但不在AppDelegate中的第一个项目?

[英]How to assign a view controller as UINavigationController's first item inside a custom class but not in AppDelegate?

我想创建一个位于navigation层次结构顶部的视图控制器HomePageViewController 但我不想在AppDelegate创建它。 我有另一个viewcontrollerMainViewController ,它分配和inits HomePageViewController

所以,首先我在AppDelegate创建MainViewController ,然后在MainViewController创建HomePageViewController

提前致谢。

  1. 创建导航控制器- (id)initWithRootViewController:(UIViewController *)rootViewController ,其中rootViewController是你的HomePageViewController

  2. 当前导航控制器- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

试试这个代码:

HomePageViewController *controller=[HomePageViewController alloc] init];
UINavigationController *navigationController=[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:navigationController animated:YES completion:Nil];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM