最簡單的方法是使用NavigationController和另一個ViewController。
在你的故事板中,選擇當前存在的ViewController。然後,點擊菜單中的「編輯器」,然後選擇「嵌入」> NavigationController。
其次,創建一個新的UIViewcontroller子類將一個UIViewController拖到故事板上。並將其在Identity Inspector中的類設置爲您剛剛創建的視圖控制器。第三,點擊ctrl-key並從第一個viewController拖到你剛剛拖到故事板上的那個。彈出窗口將會顯示。點擊「推」。你剛剛創建了一個segue。恭喜:)
單擊segue(ViewControllers之間的界限)並在屬性檢查器中爲其指定一個標識符。
接下來,在你的代碼,這樣做([SEGUE-符]是你剛纔給的標識符。):
[self performSegueWithIdentifier:@"[segue-identifier]" sender:self];
....
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"[segue-identifier]"])
{
second *controller=[segue destinationViewController];
//do stuff with the new controller here, for instance: delegation.
}
}
就是這樣,我認爲!希望我沒有忘記任何重要的;)
您不需要的代碼執行SEGUE因爲故事板將做到這一點了,但我想不出你錯過了什麼。好的答案和我的另一種選擇 - OP現在可以選擇是否需要導航或模態視圖。 – jrturton 2011-12-22 08:16:57
對不起,收回我評論的第一部分 - 如果您只是將其從一個視圖控制器連接到下一個視圖控制器,則需要執行代碼才能執行segue。我以爲你會說從一個按鈕連接它。 – jrturton 2011-12-22 09:01:14