2017-03-02 75 views
-1

我有一個應用程序,用戶可以跳過登錄。裏面有一個uitabbar控制器,其中一個視圖控制器顯示用戶配置文件,如果用戶登錄。但是,如果用戶跳過登錄,單擊配置文件選項卡上必須顯示登錄屏幕。我怎樣才能做到這一點。根據條件在tabbarcontroller中更改viewcontroller

在此先感謝

回答

0

請在下面code嘗試,設置BOOL variable根據自己的需要。欲瞭解更多信息。你提到This link

BOOL isLogin; 
NSMutableArray *tbViewControllers = [NSMutableArray arrayWithArray:[self.tabBarController viewControllers]]; 

UIViewController *message = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil] ; 
[tbViewControllers addObject:message]; 
if(isLogin){ 
    UIViewController *profile = [[ProfileVC alloc] initWithNibName:@"ProfileVC" bundle:nil] ; 
    [tbViewControllers addObject:profile]; 
}else{ 
    UIViewController *LoginVC = [[LoginVC alloc] initWithNibName:@"LoginVC" bundle:nil] ; 
    [tbViewControllers addObject:LoginVC]; 
} 


UIViewController *more = [[[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil] autorelease]; 
[tbViewControllers addObject:more]; 

[self.tabBarController setViewControllers:tbViewControllers];