views:

599

answers:

1

Hi, 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! ...
}
+1  A: 

So I fixed it by completely removing initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil from my timerPickerViewController and used viewDidLoad instead and everything is fine! Hope that helps someone else.

taber