2014-02-28 51 views
1

我明白這個問題很多時候在STackOverflow上,也有很多在互聯網上。我也問過相關的問題是相同的,但環境不同,請耐心等待,因爲我無法找到解決此任務的方案。iOS:無法顯示登錄成功之前的登錄

我正在使用Xcode 5,使用Storyboard。我的項目是基於Tab的,並在故事板中添加了一個LoginViewController。我的勝利是在Tabs之前顯示LoginViewController。我嘗試了幾種來自不同網站的方式,但沒有完全適用。有了這段代碼,我可以首先獲得LoginViewController,但無法獲得Tabs控制器。在我的AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Override point for customization after application launch.  
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; 
self.tabBarController = [[MC_MainTabBarController alloc] init]; 

LoginViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:@"loginViewController"]; 
[self.window setRootViewController:loginViewController]; 

// This also works - it shows the login 
//[[[[UIApplication sharedApplication] delegate] window] setRootViewController:loginViewController]; 

// With this Login doesn't come only 
//[loginViewController setModalPresentationStyle:UIModalPresentationFullScreen]; 
//[tabCtrler presentViewController:loginViewController animated:NO completion:nil]; 

return YES; 
} 

在我LoginViewController.m - 在結束loginBtnClicked事件,我呼籲:

NSLog(@"Showing TabController"); 
MC_AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; 
[appDelegate.window setRootViewController:appDelegate.tabBarController]; 

在上述各行的執行,我得到黑色的屏幕和下面的警告:

Showing TabController 
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation. 
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation. 

任何人都可以請幫助我。我從最近2天就陷入了這個問題。

任何幫助,高度讚賞。

+1

也許我的回答可以幫助你:http://stackoverflow.com/questions/19962276/best-practices-for-storyboard-login-screen-handling-clearing-of-data-upon-logou/21877460#21877460 –

+0

@dimimpou,非常感謝。你的回答幫了我。也有通知的想法。雖然我爲我的問題實施了特雷弗格曼的回答,但也從您的回答中採納了想法。謝謝。 – Tvd

+1

很高興我能幫到你。 –

回答

2

你確定MC_MainTabBarController是UITabBarController的子類嗎? (我猜是這樣) ,因爲當TabBar不是rootViewController時會出現這個錯誤

而不是[[MC_MainTabBarController alloc] init];我會從storyboard [storyboard instantiateViewControllerWithIdentifier:@「myTabBarIdentifier」]分配標籤欄控制器;

我試着和它的工作對我來說:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    _tabController = [storyboard instantiateViewControllerWithIdentifier:@"tabbcontrolllerid"]; 
    LoginViewController *login = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil]; 
    [_window setRootViewController:login]; 
    return YES; 
} 

和你一樣在登錄

- (IBAction)goToApp:(id)sender { 
    stackAppDelegate *app = [UIApplication sharedApplication].delegate; 
    [app.window setRootViewController:app.tabController]; 
} 

的按鈕對於信息的標籤欄是一個自定義TabBarController是的UITabBarController 的子類我已經在故事板中設置了自定義選項卡的標識符。

+0

感謝您的快速解決方案。是的,啓動我的tabController是個問題。我實現了這個方法,它確實有效。雖然我實現Trevor Gehman在dimimpou中顯示的答案鏈接,但概念如您所述 - 將storyboardId提供給TabController並通過故事板初始化。再次感謝。 – Tvd