2012-04-24 71 views
1

我想弄清楚如何顯示登錄(模態viewcontroller)從註銷按鈕和自動卸載設置(模態viewcontroller)從下面的登錄。您可能會看到故事板佈局:如何顯示登錄和解除設置 - 故事板

http://cl.ly/2B3h0T130S1K1026201N

我試圖將此代碼添加到註銷方法SettingsViewController.m

- (IBAction)logoutAccount { 

     [self dismissModalViewControllerAnimated:YES]; 

     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
     UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; 
     [vc setModalPresentationStyle:UIModalPresentationFullScreen]; 

     [self presentModalViewController:vc animated:YES]; 

} 

的問題是,它迫使我的應用程序凍結時,我點擊登出。有人知道它有什麼問題嗎?任何建議表示讚賞。

回答

0

用戶再次登錄後,您希望應用程序在哪裏?假設您希望應用程序位於設置按鈕所在的視圖控制器(從故事板看起來如此)。

然後是VC(導航控制器根VC)可以做到這一點:

- (void)viewDidAppear:(BOOL)animated { 

    if (/*login is needed*/) { 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
     UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; 
     [vc setModalPresentationStyle:UIModalPresentationFullScreen]; 

     [self presentModalViewController:vc animated:YES]; 
    } else { 
     // normal view did appear logic 
    } 
} 

註銷按鈕現在可以只是這樣做:

- (IBAction)logoutButtonPressed:(id)sender { 
    [self.navigationController popToRootViewControllerAnimated:NO]; 
} 
+0

明白了!現在它正在工作。非常感謝! – hightech 2012-04-24 19:56:32

+0

我還有一個關於將PasscodeViewController添加到其中的問題。你可能會看到這個問題,我張貼在http://stackoverflow.com/questions/10307120/display-passcode-pincode-upon-launching-the-app-storyboard你的幫助非常感謝!謝謝! – hightech 2012-04-24 22:54:44

+0

現在就看看。 – danh 2012-04-24 23:50:16