[英]How to set UIVIewController to RootViewController?
我想知道我們如何在UINavigationController中設置UIViewController而不使用UITableView為其根視圖控制器。 有什么幫助嗎? 提前致謝。
您可以按照以下步驟進行操作:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
UIViewController *myViewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
self.window.rootViewController = navigationController;
// ...
}
您可以替換myViewController
和/或使用筆尖初始化它。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:[[OptionViewController alloc]initWithNibName:@"OptionViewController" bundle:nil]];
self.window.rootViewController=nav;
self.window.backgroundColor = [UIColor grayColor];
[self.window makeKeyAndVisible];
return YES;
}
它為我工作:
在窗口上設置tabviewcontroller,它將正常工作。
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UITabBarController *tabVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MyMainView"];
[window setRootViewController:tabVC];
UINavigationController pushViewController:動畫化:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.