2012-03-14 56 views
0

我是新來的iPhone應用程序開發如何將數據傳遞給xCode中的另一個故事板?

我有一個關於如何從一個視圖(XIB文件)的數據傳遞到另一個故事板的問題?

例如,

我有「welcome.xib」,其中包含nameTextfield和Next按鈕,用戶輸入他們的名字進入nameTextfield,然後單擊下一步

應用程序將導航到「main.storyboard」和顯示器從nameTextfield.text上userNameLabel在「main.storyboard」文本

我所知道的,到目前爲止: -

  • 我知道如何通過視圖之間的數據(從一個XIB文件到另一個XIB文件)
  • 我知道如何從視圖(XIB文件)導航到另一個故事板

在此先感謝! :)

+1

「我知道如何在視圖之間傳遞數據(從一個xib文件到另一個xib文件)」......所以你的問題是什麼?似乎你已經知道答案。 – Canopus 2012-03-14 17:49:32

+0

如果您正在使用故事板,爲什麼要爲您的歡迎視圖控制器創建一個單獨的xib,而不是將它作爲main.storyboard的一部分包含在其中? – jonkroll 2012-03-14 18:24:25

回答

1

覆蓋您希望傳遞信息的ViewController中的-prepareForSegue:sender:方法。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    DetailViewController *sc = [segue destinationViewController]; 
    // Here you can set variables in detailViewController. For example if you had a NSString called name 
    sc.name = @"name_here"; 
    // Or you could do 
    [sc setName:@"name_here"]; 
} 
相關問題