tags:

views:

1134

answers:

3

I have tried using the obvious method as outlined in the following example but my passed variable (rootcategory) is still nil on viewDidLoad in the loaded view

http://www.iphonesdkarticles.com/2008/08/table-view-tutorial-part-3.html

This is my code:

CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:[NSBundle mainBundle]];
self.categoryViewController.rootCategory = @"433";
self.categoryViewController = viewController;
[viewController release];

I am synthesizing a property in the header as follows:

@property (nonatomic, readwrite) NSString *rootCategory;
A: 

What does your header file for CategoryViewController look like? Did you define rootCategory as a property? Is it synthesized or did you write your own setter and getter?

Andy Bourassa
added snippet in question
tigermain
+3  A: 

You are allocating viewController, and try to change self.categoryViewController before it is assigned to viewController.

CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:[NSBundle mainBundle]];
viewController.rootCategory = @"433";
self.categoryViewController = viewController;
[viewController release];

should work.

Stephan Burlot
hasn't helped Im afraid made no difference
tigermain
would you mind telling me the difference between using self and not, Im guessing its not like this. in c# (my background)
tigermain
What are @property of rootCategory and categoryViewController?rootCategory should be "copy" or "retain" and categoryViewController should be "retain".Using self means use the defined setter (via @property, in this case)
Stephan Burlot
change your property to:@property (nonatomic, readwrite, copy) NSString *rootCategory;and make sure your categoryViewController has "retain" property.
Stephan Burlot
sorry Stephen your amends were correct the key part was assigning to the viewController and not self.viewController. Not sure how my test failed before
tigermain
A: 

I believe that viewDidLoad is called on the new instance before initWithNibName: returns, so you'd be setting your properties after it's called.

iKenndac
So which method could I put my execution code in to pick up the variable in?
tigermain