iphone 2.x sdk - reference to a viewController inside another viewController showing up as null
-
03-07-2019 - |
Question
I'm trying to give a newly created instance of a custom picker view controller a reference to another viewController like so (this is inside of a selector from a ponceViewController instance that is called after a tableView row is tapped)...
- (IBAction)rowTapped:(id)sender {
TimerPickerViewController *viewController = [[TimerPickerViewController alloc] initWithNibName:@"TimerPickerView" bundle:nil]
self.timerPickerViewController = viewController;
timerPickerViewController.ponceViewController = self.rootViewController;
[viewController release];
}
Then inside my timerPickerViewController instance I have:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
...
// ponceViewController is null here
...
}
}
The timerPickerViewController displays just fine, and I can even access stuff from ponceViewController after I tap my "Done" button, but I'm synthesizing ponceViewController and it's in my header and everything, and I can't seem to access it inside of timerPickerViewController's initWithNibName method - it's always null. :( Anyone have any ideas?
Edit: I should also mention that ponceViewController is null inside timerPickerViewController's viewDidLoad method as well...
- (void)viewDidLoad {
... no such thing as ponceViewController here! ...
}
Solution
So I fixed it by completely removing initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
from timerPickerViewController and used viewDidLoad
instead. Everything seems to work fine. I think the issue was that the property wasn't available yet when referencing it inside initWithNibName
. Hope that helps someone else.