xcode 在 ios5 故事板 segue + UITableview 中传递参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7977321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:18:30  来源:igfitidea点击:

passing parameter in ios5 storyboard segue + UITableview

xcodeios5uitableview

提问by moon

I was to pass a NSString from RootViewController(UITableViewController) to DetailViewController .

我要从 RootViewController(UITableViewController) 传递一个 NSString 到 DetailViewController 。

t RootViewController.m

t RootViewController.m

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    DetailViewController *detailViewController = segue.destinationViewController; 
    detailViewController.name = @"foo"; 
    }

DetailViewController.h:

DetailViewController.h:

NSString *name;
@property (nonatomic,strong) NSString *name;

DetailViewController.m

DetailViewController.m

@synthesize name = _name;
NSLog(@"%@", name);

The result of NSlog is null. Appreciate for any hint. Thanks a lot.

NSlog 的结果为空。感谢任何提示。非常感谢。

回答by Sharky

I can't really see when you are executing your nslog. So i'm thinking you ask for the name before you are setting it.

我真的看不到你什么时候执行你的 nslog。所以我想你在设置之前询问名称。

And another thing. If you write:

还有另一件事。如果你写:

@synthesize name = _name;

you should use this too:

你也应该使用这个:

NSLog(@"%@", _name);

回答by ifredy2

you can view the sample passing data from cellto detailViewControllerat YouTube.

您可以在 YouTube查看从cellto传递数据的示例。detailViewController