2014-09-04 48 views
-1

正如您在圖片上看到的那樣,在正常情況下,我單擊button1調用第二個視圖,然後單擊button2調用最後一個視圖,在特定場景中,我想單擊button1調用最後一個視圖。 我說這對梅索德viewDidLoad中:如何以編程方式從不相關的View Controller調用View Controller?

if(condition) 
    [self performSegueWithIdentifier:@"thirdview" sender:self]; 

,但它不能正常工作,任何幫助,請。

謝謝。 enter image description here

回答

3

您需要添加從ViewController1Viewcontroller3的繼續。

但是,如果你用很多viewControllers做到這一點,那麼它變得凌亂,我稱之爲spaguetti塞格斯。

另一種方法是以模態方式顯示viewController

例子:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; 
ViewController3 *viewController = 
     [storyboard instantiateViewControllerWithIdentifier:@"viewController"]; 
[self presentViewController:viewController animated:YES completion:nil]; 

(確保你給ViewController3一個storyboardId

+1

我同意這個答案。通過故事板ID加載視圖是一種乾淨的方式來處理這種獨特的情況。我不認爲一個UI元素可以有多於一個的連接。 – 2014-09-04 16:12:44

相關問題