如何将值从一个 Controller 传递到另一个???我使用 Storyboard。
我希望它出现在第一个 View 的突出显示 TextView 中。
调用代码的下一个 View ,我认为像这样的东西应该是这样的:
UIStoryboard *finish = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *viewController = [finish instantiateViewControllerWithIdentifier:@"FinishController"];
viewController.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:viewController animated:YES];
完成 Controller :
- (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.
}
第一 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";
}
}
我想传递一个值导致代码的传输
最佳答案
问题是您实际上并没有使用那个 segue,而是使用了 presentModalController
。
请注意,通常情况下,您可以向 self
询问 Storyboard。然而,当你有一个 segues 连接时,即使那样也是不必要的:
[self preformSegueWithIdentifier:@"FinishController" sender:self];
然后调用 prepareForSegue 。另请注意,您可以(应该)使用比 segue 标识符更权威的东西来确定您是否应该加载数据......您可以询问 segue 的目标 Controller 它是否是正确的类:
-(void) prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender
{
if ([segue.destinationViewController isKindOfClass:[FinishController class]]) {
FinishController *asker = (FinishController *) segue.destinationViewController;
asker.FinishDesc = @"What do you want your label to say?";
asker.FinishTitle = @"Label text";
asker.FinishPoint = @"asdas";
}
}
您可能已经知道(因为您在代码中使用了标识符),但为了这篇文章的 future 发现者的利益;当您在 Storyboard 中时,在 Xcode 的检查面板中会为 segues 提供标识符。
关于iphone - 使用 segue 将数据传输到另一个 Controller 。从代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11464155/