如何使用导航将字符串从一个tableViewController传递到其他tableViewController

时间:2011-11-18 13:18:09

标签: ios string uitableview uinavigationcontroller xcode4.2

我看了但没找到合理的答案。我有一个第一个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

1 个答案:

答案 0 :(得分:2)

将第二个TableViewController的.h文件及附带的代码(例如@synthesise)添加到.m文件中。当您分配/初始化第二个TableViewController时(从第一个开始),在将控制器推入导航堆栈之前设置属性。

您可以在Objective-C here找到属性简介。