【发布时间】:2016-06-29 01:11:46
【问题描述】:
我已经有一个带有 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];
}
【问题讨论】:
标签: ios objective-c uiviewcontroller uinavigationcontroller uitabbarcontroller