TabBarController,覆盖 shouldSelectViewController 来做一个 segue [英] TabBarController, overwriting shouldSelectViewController to do a segue

查看:22
本文介绍了TabBarController,覆盖 shouldSelectViewController 来做一个 segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi Im trying to change the tabcontroller flow, so when a user is not loged in just take him to the login view instead the settings one. My controller extends TabBarController and I set the delegate as

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;
    }

我从来没有设法做它给异常的导航:

I never manage to do the navigation it gives an excetion :

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

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

I also tried to show the login in as a modal but it only shows a black screen:

- (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;
    }
}

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

Can anybody help Me!!!! please!!!!

推荐答案

好吧,我设法修复了黑色模态屏幕(仍然无法进行非模态的转场).问题是,当我使用故事板时,我必须按如下方式从故事板加载视图.

Well I manage to fix the black modal screen (still cant d a segue that is not modal). The problem was that as I am using storyboard I have to load the view from story board as follows.

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *navController = [storyboard instantiateViewControllerWithIdentifier:@"login"];

    [navController setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:navController animated:YES];

成功了 :)

这篇关于TabBarController,覆盖 shouldSelectViewController 来做一个 segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆