iphone - tableView didSelectRow not properly functioning -


my other question ambiguous make 1 clearer. have table view on 1 viewcontroller , when cell selected, saves number nsuserdefaults. on main viewcontroller, retrieve number , want update label it. did debugging , found when go main viewcontroller tableview one, order @ happens:

1) main view loads 2) tableview cell tap recognized 3) number saved nsuserdefaults

how change order main view loads last when click cell, changes label in main viewcontroller?

here code didselectrow method

 - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath  {  nsstring *pointspath = [[nsstring alloc] initwithformat:@"totalpoints"];  nsstring *numberfirst = [[nsstring alloc] initwithformat:@"numberfirst"];  int totalpoints = [[nsuserdefaults standarduserdefaults] integerforkey: pointspath]; int number = [[nsuserdefaults standarduserdefaults] integerforkey:numberfirst];  if([indexpath row] == 1) {     nslog(@"selected first row");     if(totalpoints < 10)     {         if (number != 0)         {             nslog(@"did not add point, saved");             [[nsuserdefaults standarduserdefaults] setinteger:1 forkey:numberfirst];             [[nsuserdefaults standarduserdefaults] synchronize];          }         else if (number == 0)         {             nslog(@"added point");             int newpoints = totalpoints + 1;             [[nsuserdefaults standarduserdefaults] setinteger:newpoints forkey: pointspath];             [[nsuserdefaults standarduserdefaults] setinteger:1 forkey:numberfirst];             [[nsuserdefaults standarduserdefaults] synchronize];             int logpoints = [[nsuserdefaults standarduserdefaults]integerforkey:pointspath];             nslog(@"point count:%i", logpoints);         }       } 

a controller's view loaded on demand. thing triggers viewdidload else performing controller.view. if you've pushed view controller container view or otherwise started present that'll agent responsible.

viewdidload, , under ios 5 , below viewdidunload, intended give hooks need if want create part of view programmatically.

if you're doing trying account setting may have been changed while controller wasn't visible, should use viewwillappear:. that's intended way determine when you're transition invisible visible.

if wanted active link between 2 things set view controller displays number listen nsuserdefaultsdidchangenotification , update views necessary when occurs.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -