【问题标题】:Getting a UITabBar after breaking out of a UINavigationBar突破 UINavigationBar 后获取 UITabBar
【发布时间】:2014-07-09 16:27:07
【问题描述】:

我有一个 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
}

【问题讨论】:

  • 您是否要导航到一个新页面(登录后),您可以在其中看到标签栏?
  • 是的,我希望导航栏消失,并使用带有几个标签的新标签栏控制器。
  • 因此,您仍然可以创建一个标签栏控制器,然后在按下登录按钮时将其与导航控制器一起推送。然后,您可以将导航栏隐藏在顶部。明白了吗?

标签: ios ios7 uitabbarcontroller uinavigationbar uitabbar


【解决方案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;

【讨论】:

  • 我有这样的,但是如何自己制作标签栏项目?
【解决方案2】:

您需要执行modalTransition 才能跳出navigationController.. 这将使AuthenticateViewController 保持为RootViewControllerRootViewController.. 如果您想更改RootViewController然后你需要获取 AppDelegate 的窗口并将其 RootViewController 更改为 TabBarController 你将在这里制作......希望你明白了..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-15
    • 2013-12-05
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多