1

In my UINavtigationController application, I have a user select a value in UITableViewController and once that is done, they are sent back to a previous UITableViewController where that value must be shown. The problem I am anticipating is that once a view is "popped", I am assuming that its viewUnload is called that gets rid of the array making it unaccessible in another view controller.

Any thoughts?

jini
  • 10,875
  • 34
  • 97
  • 167

3 Answers3

2

You need to pass the new value to previous controller from your didSelectRowIndex function by using anyone of the approaches

1-> Using NSUserDefault.

iPhone Programming Tutorial – Saving/Retrieving Data Using NSUserDefaults

2-> Using Delegate concept.

3-> you could also access the previous ViewController from you UINavigationController methods.

Community
  • 1
  • 1
Jhaliya - Praveen Sharma
  • 31,542
  • 8
  • 70
  • 75
1

You can access the first view controller via self.parentViewController, so it would be best to synthesize an array in the first view, then set it before you call popViewControllerAnimated: in the second. Basically it would look like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.parentViewController setNewArray:myArray];
    [self.navigationController popViewControllerAnimated:YES];
}

Just make sure you have NSArray *newArray; and @property (nonatomic, retain) NSArray *newArray specified in the first view's header file and synthesized in the implementation file

justin
  • 5,821
  • 3
  • 28
  • 32
0

you can use NSUserDefaults to achieve the same

yogs
  • 758
  • 2
  • 10
  • 29