0

I've got a very stupid problem. I have a TableView where I'd like to make each cell editable by pushing into a DetailController. It's working so far, but when I do

NSLog(@"selectedItem: %@", selectedItem_);

in viewDidLoad, the log displays:

selectedItem: (null)
selectedItem: Toe

RootViewController (didSelectRowAtIndexPath):

NSString *selectedItem = [content objectAtIndex:indexPath.row];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
detailViewController.selectedItem_ = selectedItem;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

DetailViewController (viewDidLoad):

NSLog(@"selectedItem: %@", selectedItem_);
[super viewDidLoad];

What am I doing wrong?

Felixyz
  • 19,053
  • 14
  • 65
  • 60
Zettt
  • 879
  • 2
  • 8
  • 27

1 Answers1

0

you cannot assume that viewDidLoad is called only once. it may be called multiple times if the view is unloaded because of memory, or when the view is getting loaded from the nib.

put the initialization in your init method.

similar question and answer on stackoverflow

viewDidLoad getting called twice on rootViewController at launch

Community
  • 1
  • 1
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80