Need help getting parent reference to child view controller

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-04-21T14:01:02Z Indexed on 2010/04/21 14:03 UTC
Read the original article Hit count: 198

I've got the following code in one of my view controllers:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
      case 0: // "days" section tapped
      {     DayPicker *dayPicker = [[DayPicker alloc] initWithStyle:UITableViewStylePlain];
           dayPicker.rowLabel = self.activeDaysLabel;
           dayPicker.selectedDays = self.newRule.activeDays;
           [self.navigationController pushViewController:dayPicker animated:YES];
           [dayPicker release];
           break;

...

Then, in the DayPicker controller, I do some stuff to the dayPicker.rowLabel property. Now, when the dayPicker is dismissed, I want the value in dayPicker.rowLabel to be used as the cell.textLabel.text property in the cell that called the controller in the first place (i.e., the cell label becomes the option that was selected within the DayPicker controller).

I thought that by using the assignment operator to set dayPicker.rowLabel = self.activeDaysLabel, the two pointed to the same object in memory, and that upon dismissing the DayPicker, my first view controller, which uses self.activeDaysLabel as the cell.textLabel.text property for the cell in question, would automagically pick up the new value of the object. But no such luck.

Have I missed something basic here, or am I going about this the wrong way? I originally passed a reference to the calling view controller to the child view controller, but several here told me that was likely to cause problems, being a circular reference. That setup worked, though; now I'm not sure how to accomplish the same thing "the right way."

As usual, thanks in advance for your help.

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about uiviewcontroller