0

I want didSelectRowAtIndexPath to execute before ViewDidLoad.

How to do it?

in didSelectRowAtIndexPath :

[[NSUserDefaults standardUserDefaults] setObject:[[array objectAtIndex:indexPath.row + 1] objectForKey:@"gid"] forKey:@"lastGID"];
NSLog(@"lastGID (saved) = %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"lastGID"]);

in viewDidLoad :

[super viewDidLoad];
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"lastGID"]);
egor.zhdan
  • 4,555
  • 6
  • 39
  • 53
  • How is that supposed to work? How can the user select a row before the view has even loaded? – Thilo Dec 08 '12 at 13:44

2 Answers2

3

If this is all happening within one view controller, you can't do it. The resources / UI of a view must be loaded (i.e. the table must be displayed and outlets connected, etc) before a row of a table can be selected.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
0

I have to use viewDidAppear instead viewDidLoad.

Hope, it will be helpful

egor.zhdan
  • 4,555
  • 6
  • 39
  • 53