2015-12-06 12 views
0

至腳本所以我找到了如何從廈門國際銀行轉變的例子,故事情節轉型與數據

NSString * storyboardName = @"CheckoutStoryboard"; 
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil]; 
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"Checkout"]; 
[self presentViewController:vc animated:YES completion:nil]; 

這個偉大的工程,然後從那裏,如果我需要轉移的故事板的場景,我可以使用之間的數據這個代碼在第一個場景中用這個來傳輸數據。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.destinationViewController respondsToSelector:@selector(setMyData:)]) { 
     [segue.destinationViewController performSelector:@selector(setMyData:)withObject:myObject]; 
    } 
} 

,這在第二

@property (nonatomic, strong) NSString *myData; 

但我無法弄清楚如何從我的XIB過渡到我的數據的故事板。基本上,我的故事板上有很多XIB上需要的變量,然後纔會傳遞出去。我知道如何做每一步,除了將數據從XIB傳遞到故事板。有任何想法嗎?

+0

XIB是你的ViewController嗎? – Burhan

回答

2

我無法爲您提供任何真實的代碼,但您不會在上述代碼中使用segues。 在您提供的示例中,您正在創建要顯示的UIViewController實例,然後以模態方式呈現該視圖控制器。

您只需直接從所需的視圖控制器實例訪問變量。

MyCustomUIViewControllerClass * vc = [storyboard instantiateViewControllerWithIdentifier:@"Checkout"]; vc.myData = <valueHere> [self presentViewController:vc animated:YES completion:nil];

+0

那麼我實例化控制器的原因是,據我所知,從XIB到故事板的唯一方法就是執行上述操作。當我嘗試你的建議的代碼時,它錯誤地告訴我,myData沒有在UIViewController中定義。 – CMOS

+0

您將其轉換爲您的ViewController類。查看更新後的答案 – AlexCatch

+0

這樣做確實有道理,我已經改變了它,但是我仍然收到錯誤,我的變量未在自定義控制器視圖的上下文中定義。我對變量的定義是否正確? @屬性(非原子,強大)NSString * myData; – CMOS