How do I get a reference from parent to child back to parent VC?

Discussion in 'iOS Programming' started by ataylor2009, Apr 21, 2010.

  1. ataylor2009 macrumors member

    Jan 27, 2009
    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];

    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.
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Are you sure your tableView is reloading its data when you come back to it?

Share This Page