3
如何將值從一個控制器傳遞給另一個?我使用StoryBoard。用segue將數據傳輸到另一個控制器。從代碼
我想這出現在第一個視圖中突出顯示的文本視圖。
調用的代碼的下一個觀點,我覺得這樣的事情應該是這樣的:
UIStoryboard *finish = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *viewController = [finish instantiateViewControllerWithIdentifier:@"FinishController"];
viewController.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:viewController animated:YES];
finishcontroller:
- (void)viewDidLoad
{
self.lblFinishTitle.text=self.FinishTitle;
self.lblFinishDesc.text = self.FinishDesc;
self.lblFinishPoint.text=self.FinishPoint;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
第一種觀點:
-(void) prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender
{
if ([segue.identifier hasPrefix:@"FinishController"]) {
FinishController *asker = (FinishController *) segue.destinationViewController;
asker.FinishDesc = @"What do you want your label to say?";
asker.FinishTitle = @"Label text";
asker.FinishPoint = @"asdas";
}
}
我想通過導致代碼傳輸的值
感謝您的快速回復!我意識到錯誤,但是當我使用:「[self preformSegueWithIdentifier:@」FinishController「];」,我得到一個錯誤:「沒有可見的@interface爲'ViewController'聲明選擇器'preformSegueWithIdentifier:'」 – Feor 2012-07-13 04:53:00
對不起,我遺漏了方法簽名的一部分......它需要第二個參數(發送者),通常你會通過這個參數來導致發生segue(比如一個按鈕,比如......但是按鈕可以直接連接到segues故事板)。 http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW83 – 2012-07-13 04:56:36
[self performSegueWithIdentifier:@「Finish」發件人:自];用過的!一切都很好!非常感謝你! – Feor 2012-07-13 04:57:39