![](/img/trans.png)
[英]How to pass data from 2nd viewcontroller to tableviewcontroller using delegates
[英]How to pass a string from one tableViewController to other tableViewController using navigation
我看了但没找到合理的答案。 我有一个第一个持有的TableViewController
,比方说4行,当用户点击一行(导航层次结构)时,我想向第二个tableViewController
传递一个字符串或一个int,它将确定第二个tableViewController
应该显示哪些数据/在第二个表上加载。 我该怎么办?
我正在使用Xcode 4.2,使用ARC但不使用故事板。
更新:
好吧,让我看看我是否明白了。 在我的第二个VC中,我会这样做
--
.h --
@property(nonatomic, strong) NSString *strReceived; --
.m --
@syntesize strReceived; --
在我的第一个视图控制器中,我会做:
--
.h --
@property (nonatomic, strong) SecondViewController *secondViewController --
.m --
@syntesize secondViewController --
然后,在方法didSelectRowAtIndexPath我会做:
--
if(indexPath.row == 1) --
self.secondViewController.strReceived = @"one"; --
else --
self.secondViewController.strReceived = @"other";
那正确吗? 由于用户可能会返回并选择另一行,我的字符串是否必须是NSMutableString
?
将属性添加到第二个TableViewController的.h文件以及随附的代码(例如@synthesise)到.m文件。 当您分配/初始化第二个TableViewController时(从第一个开始),在将控制器推入导航堆栈之前设置属性。
您可以在此处找到Objective-C中的属性介绍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.