【问题标题】:TabBarController, overwriting shouldSelectViewController to do a segueTabBarController,覆盖 shouldSelectViewController 做一个 segue
【发布时间】:2012-03-06 18:17:28
【问题描述】:

您好,我正在尝试更改 tabcontroller 流程​​,因此当用户未登录时,只需将他带到登录视图而不是设置视图。我的控制器扩展了 TabBarController 并将委托设置为

self.tabBarController.delegate=self;

我的代码是:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

    if (login) {

        LoginViewController *loginViewController = [[LoginViewController alloc] init];
        UINavigationController *navController = [[UINavigationController alloc]
                                                 initWithRootViewController:loginViewController];


        [tabBarController presentViewController:loginViewController animated:YES completion:nil];
               return NO;
    } else {
        return YES;
    }

我从来没有设法完成它给出的导航:

ion 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UITabBarController: 0x6a72220>.

我也尝试将登录显示为模式,但它只显示黑屏:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

    if (YES) {
        LoginViewController *loginViewController = [[LoginViewController alloc] init];
        UINavigationController *navController = [[UINavigationController alloc]
                                                 initWithRootViewController:loginViewController];


        [tabBarController presentModalViewController:navController animated:YES];
               return NO;
    } else {
        return YES;
    }
}

谁能帮帮我!!!!请!!!!

【问题讨论】:

    标签: uitabbarcontroller xcode4.2


    【解决方案1】:

    好吧,我设法修复了黑色模态屏幕(仍然无法找到非模态的 segue)。 问题是,当我使用情节提要时,我必须从情节提要中加载视图,如下所示。

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *navController = [storyboard instantiateViewControllerWithIdentifier:@"login"];
    
        [navController setModalPresentationStyle:UIModalPresentationFullScreen];
    
        [self presentModalViewController:navController animated:YES];
    

    成功了 :)

    【讨论】:

    • 这在 iPhone 上对我不起作用。我必须执行以下操作:将 modalPresentationStyle 设置为 UIModalPresentationFormSheet 并将 modalTransitionStyle 设置为 UIModalTransitionStyleCrossDissolve。
    猜你喜欢
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 2016-11-18
    相关资源
    最近更新 更多