2011-11-18 96 views
0

我已經看過,但還沒有找到合理的答案。我有一個第一個TableViewController,保存,可以說4行,當用戶點擊一行(導航層次結構),我想傳遞給第二個tableViewController一個字符串或一個int,將確定哪些數據第二個tableViewController應該顯示/加載在第二張桌子上。我會怎麼做?如何將字符串從一個tableViewController傳遞到使用導航的其他tableViewController

我使用的Xcode 4.2,使用ARC,但不使用故事板。

更新:

OK,讓我們看看,如果我得到了它。 在我secondVC,我將在第一視圖控制器不

-- 
.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

回答

2

將屬性添加到您的第二個TableViewController的.h文件和隨附的代碼(例如@synthesise)到.m文件中。當你分配/初始化你的第二個TableViewController(從第一個),在將控制器推入導航棧之前設置屬性。

您可以在Objective-C here中找到屬性的介紹。

相關問題