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

    Joined:
    Jan 27, 2009
    #1
    I've got the following code in one of my view controllers:

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

    dejo

    Staff Member

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

Share This Page