我有一个UINavigationBar,里面有一个AuthenticateViewController。然后当用户登录导航控件的右上角时,我想显示一个UITabBar控制器。我还在appDelegate中创建吗?如何“突破”UINavigation控制器?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Add methods for layout of this view controller here
//1
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
//2
self.managedObjectContext = appDelegate.managedObjectContext;
[self.navigationItem setHidesBackButton:YES];
// Now add the Sign In button
UIBarButtonItem *signinButton = [[UIBarButtonItem alloc] initWithTitle:@"Sign In" style:UIBarButtonItemStylePlain target:self action:@selector(signinButtonPressed:)];
self.navigationItem.rightBarButtonItem = signinButton;
}
- (void) signinButtonPressed:(UIBarButtonItem *) sender
{
// What goes here to start the UITabBars
}
答案 0 :(得分:1)
登录后将TabBarController
设为rootViewController
。
您的按钮操作如下:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = @[<your viewControllers>];
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window setRootViewController:tabBarController];
编辑:您可能无法使用@[]
创建数组。所以这是一个解释:
UIViewController *viewController1 = [[UIViewController alloc] init];
UIViewController *viewController2 = [[UIViewController alloc] init];
// Two methods of adding item to array
// First method
NSArray *array = [NSArray arrayWithObjects:viewController1, viewController2, nil];
// or
NSArray *array = @[viewController1, viewController2];
tabBarController.viewControllers = array;
答案 1 :(得分:0)
您需要modalTransition
跳出navigationController
..这会将AuthenticateViewController
保持为RootViewController
window
RootViewController
如果您想要更改RootViewController
,那么您需要获取AppDelegate的窗口,并将其TabBarController
更改为{{1}}您&#39}在这里做...希望你明白了......