iOS 5 segue实现 [英] iOS 5 segue implementation

查看:66
本文介绍了iOS 5 segue实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在两个视图控制器之间实现segue时如何使用segue对象更改目标视图控制器的属性?文档说这可以在prepareForSegue:sender:方法中完成。我尝试了但不是没有成功

While implementing a segue between two view controllers how to change a property of the destination view controller using the segue object? The documentation says that this can be done inside the prepareForSegue: sender: method. i tried it but not was not successful

推荐答案

如果你还需要一个答案,但是这是一个如此孤独的帖子,如果我是正确的,这不再属于NDA。如果我弄错了,请将我的答案放在遗忘之中,所以我们走了:我刚刚完成了一些使用你需要的东西。这是适合我的代码:

Dunno if you still need an answer to this, but it was such a lonely post, and if I'm correct, this doesn't fall under NDA any longer. If I'm mistaken, please moderate my answer into oblivion, so here we go: I just finished doing something that uses what you need. This is code that works for me:

- (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都是合成的访问者目标视图控制器。希望这有帮助!

This assumes that both someProperty and initialViewController are synthesized accessors of the destination view controller. Hope this helps!

这篇关于iOS 5 segue实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆