gpt4 book ai didi

storyboard - iOS 5 segue实现

转载 作者:行者123 更新时间:2023-12-03 17:04:50 26 4
gpt4 key购买 nike

在两个 View Controller 之间实现segue时,如何使用segue对象更改目标 View Controller 的属性?该文档说,这可以在prepareForSegue:sender:方法中完成。我尝试过,但没有成功

最佳答案

我不知道您是否仍然需要答案,但这是一个很寂寞的帖子,如果我是正确的话,这不再属于NDA。如果我弄错了,请忽略我的回答,这样我们就可以开始了:我刚刚完成了可以使用您需要的操作。这是对我有用的代码:

- (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都是目标 View Controller 的综合访问器。希望这可以帮助!

关于storyboard - iOS 5 segue实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7595374/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com