在两个视图控制器之间实现 segue 时,如何使用 segue 对象更改目标视图控制器的属性?文档说这可以在prepareForSegue:sender:方法中完成。我尝试过但没有成功
我不知道你是否还需要这个答案,但这是一个如此孤独的帖子,如果我是对的,这不再属于保密协议。如果我错了,请缓和我的答案,让我们忘记,所以我们开始:我刚刚完成了一些使用你需要的东西。这是适合我的代码:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"relevantSegueIdentifier"])
{
// [segue destinationViewController] is read-only, so in order to
// write to that view controller you'll have to locally instantiate
// it here:
ViewController *upcomingViewController = [segue destinationViewController];
// You now have a solid reference to the upcoming / destination view
// controller. Example use: Allocate and initialize some property of
// the destination view controller before you reach it and inject a
// reference to the current view controller into the upcoming one:
upcomingViewController.someProperty = [[SomePropertyClass alloc] initWithString:@"Whatever!"];
upcomingViewController.initialViewController = [segue sourceViewController];
// Or, equivalent, but more straightforward:
//upcomingViewController.initialViewController = self;
}
}
这假设 someProperty 和initialViewController 都是目标视图控制器的合成访问器。希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)