2

我有一個HomeController允許用戶登錄和註冊。如果用戶點擊登錄,我使用segue打開模態視圖。關閉模態視圖然後執行segue打開第二個模態視圖

模態視圖內有一個表示註冊的按鈕。期望動作是關閉的登錄模式的看法,然後使用performSegueWithIdentifier:

- (void)loginControllerDidRegister:(LoginController *)controller sender:(id)sender 
{ 
    NSLog(@"loginControllerDidRegister"); 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    [self performSegueWithIdentifier:@"RegistrationSegue" sender:sender]; 
} 

這正確駁回了模態視圖打開註冊模式的看法,然後調用performSegueWithIdentifier:,在那裏我有記錄代碼,顯示它被稱爲只是就好像我已經按下了註冊按鈕。

我認爲登錄模式視圖消失的動畫可能會干擾第二個模態視圖的顯示。任何想法可以做什麼來解決這個問題?

+0

不回答您的具體問題,但作爲一個兩級視圖序列的問題,我不喜歡多個動畫 - 太分心+隱含不同的環境 - 所以我最終填充與滾動視圖既觀看階段,又以模態方式呈現。在模式滾動視圖中以編程方式滑動到第二個視圖效果很好。所以,針對類似問題採取不同的解決方 –

回答

2

你需要啓動你的「第二模態」vc。這就是「prepareForSegue:」方法的作用。你也需要重寫「perform:」方法。這會比你想象的要複雜一些。如果有幫助,這裏是一個賽格如何工作的細分...

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender; 

被調用並通過「segue」。在幕後

- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)source; 

被調用,這就是創建「segue」的地方。

的 「SEGUE」 對象與這些不能執行一個賽格瑞的

(NSString *)identifier 
(UIViewController *)sourceViewController 
(UIViewController *)destinationViewController 

性質。這些類似於手工分配視圖控制器

SomeViewController *secondView = [SomeViewController alloc] initwithNibName:@"SomeViewController" bundle:nil]; 

然後

[[segue destinationViewController] setModalTransitionStyle:UIModalTransitionStyle(...)]; 

這是...

secondView.modalTransitionStyle = UIModalTransitionStyle(...); 

的(......)將是 「SEGUE」 過渡選擇在故事板中。

最後

[[segue sourceViewController] presentModalViewController:destinationViewController animated:YES]; 

這只是

[self presentModelViewController:secondView animated:YES]; 

是什麼讓這一切發生。你將基本上不得不與那些在發動機罩下工作的人一起調整,以獲得你想要的工作,但它是可行的。

0

您必須將第二個模態視圖控制器的performSegue放置在dismissViewControllerAnimated調用的完成塊中。 UINavigationController在呈現其他模式視圖控制器時無法處理演示文稿。

0

如果有人有同樣的問題。

- (void)loginControllerDidRegister:(LoginController *)controller sender:(id)sender 
{ 
    NSLog(@"loginControllerDidRegister"); 
    [self dismissViewControllerAnimated:YES completion:^{ 
     [self performSegueWithIdentifier:@"RegistrationSegue" sender:sender]; 
    }]; 
} 
+1

這不應該/不會工作,因爲如果你的「自我」不在那裏,你就無法執行一次繼續 –

相關問題