2012-03-06 50 views
0

嗨我試圖改變tabcontroller流量,所以當一個用戶沒有在只是把他帶到登錄視圖而不是設置之一。我的控制器擴展TabBarController和我設置的委託作爲TabBarController,覆蓋shouldSelectViewController做一個segue

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

我從來沒有設法做導航它提供了一個EXCETION:

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

任何人都可以幫助我!!!!請!!!!

回答

2

那麼我設法修復黑色模態屏幕(仍然不能不是模態的賽格)。 問題是,因爲我正在使用故事板,我必須從故事板加載視圖,如下所示。

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

    [navController setModalPresentationStyle:UIModalPresentationFullScreen]; 

    [self presentModalViewController:navController animated:YES]; 

這使的伎倆:)

+0

這並沒有對iPhone爲我工作。我必須執行以下操作:將modalPresentationStyle設置爲UIModalPresentationFormSheet,並將modalTransitionStyle設置爲UIModalTransitionStyleCrossDissolve。 – 2012-11-07 23:50:41