[英]Switching root view controller
我已經有一個帶有UINavigationController的應用程序,但是我想切換到UITabBarController,問題是當我從一開始切換到UItab時它不起作用,所以我在委托方法中切換了它,但是它也不起作用! 應用程序委托中的所有代碼 。
self.navigationController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
self.tabBarController = [[UITabBarController alloc] init];
if ([PFUser currentUser]) {
// Present wall straight-away
[self presentWallViewControllerAnimated:NO];
} else {
// Go to the welcome screen and have them log in or create an account.
[self presentLoginViewController];
}
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
我想打開它的委托方法:
- (void)presentWallViewControllerAnimated:(BOOL)animated {
NSLog(@"Called:presentWallViewControllerAnimated ");
// self.navigationController = nil;
self.tabBarController = [[UITabBarController alloc] init];
PAWWallViewController *wallViewController = [[PAWWallViewController alloc] initWithNibName:nil bundle:nil];
wallViewController.delegate = self;
// Set up the first View Controller
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.view.backgroundColor = [UIColor orangeColor];
vc1.tabBarItem.title = @"Orange";
vc1.tabBarItem.image = [UIImage imageNamed:@"heart"];
// Set up the second View Controller
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.view.backgroundColor = [UIColor purpleColor];
vc2.tabBarItem.title = @"Purple";
vc2.tabBarItem.image = [UIImage imageNamed:@"star"];
// Set up the Tab Bar Controller to have two tabs
[self.tabBarController setViewControllers:@[ vc1, vc2]];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
// [self.window addSubview:tabBarController.view];
// [self.navigationController setViewControllers:@[ tabBarController ] animated:animated];
}
記住要處理視圖轉換:
UIViewController *vc = // any vc that's initialized properly
window.rootViewController = vc;
[UIView transitionWithView:window
duration:0.3 // 0.0 for immediate
options:UIViewAnimationOptionTransitionCrossDissolve // several enums to choose from here
animations:nil
completion:nil];
而且您在第一次之后就不需要makeKeyAndVisible
了。
您調用了- (void)presentWallViewControllerAnimated:(BOOL)animated
但在您調用的didFinishLaunchingWithOptions
結尾時
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
因此,標簽欄將永遠無法工作!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.