newton_guima
newton_guima

Reputation: 1569

How to pass a string from one tableViewController to other tableViewController using navigation

I have looked but haven't found a reasonable answer. I have a first TableViewController that holds, lets say 4 rows, and when the user taps in one row (navigation hierarchy), i want to pass to the second tableViewController a string or an int that will determine which data the second tableViewController should show/load on its second table. How would I do that?

I am using Xcode 4.2, using ARC but NOT using storyboard.

Update:

ok, lets see if i got it. in my secondVC, i will do

--
.h --
@property(nonatomic, strong) NSString *strReceived; --
.m --
@syntesize strReceived; --

in my first view controller i will do:

--
.h --
@property (nonatomic, strong) SecondViewController *secondViewController --
.m --
@syntesize secondViewController --

and then, in the method didSelectRowAtIndexPath i will do:

--
if(indexPath.row == 1) --
self.secondViewController.strReceived = @"one"; --
else --
self.secondViewController.strReceived = @"other";

is that right? since the user may go back and choose another row, does my string need to be a NSMutableString?

Upvotes: 0

Views: 257

Answers (1)

Nathanial Woolls
Nathanial Woolls

Reputation: 5291

Add a property to your second TableViewController's .h file and the accompanying code (e.g. @synthesise) to your .m file. When you alloc/init your second TableViewController (from the first), set the property before pushing the controller onto the navigation stack.

You can find an intro to properties in Objective-C here.

Upvotes: 2

Related Questions