ios - Can't update a tableview automatically -


i have view controller many views , tableview.

the tableview's cells customized, there class setting cells. in each cell there button. image of button changes depending on cell's content (this content gets read db).

basically, when user presses button, changes image, new status written db tableview not update automatically.

the method button in custom cell class, i've tried instantiate view controller (the 1 tableview) , execute method updating labels in views , tableview:

viewcontrollerwithtable *vc = [[viewcontrollerwithtable alloc] init]; [vc updateeverything]; 

but doesn't work. same "updateeverything" method, called same "viewcontrollerwithtable" (adding reload button) works perfectly. adding "[tableview reloaddata]" in viewwillappear method won't work because action done in same view.

what missing?

edit: adding code more clear.

this method use update tableview. it's inside viewcontroller embedded tableview , works when triggered button in 1 of views:

- (void) updateeverything {     // lots of db writing , reading, plus label text changing inside views     [tableview reloaddata];  } 

this ibaction button press , it's in custom cell class:

-(void) btnpresapressed:(uibutton *)sender {     appdelegate *deleg = (appdelegate *)[[uiapplication sharedapplication] delegate];     deleg.did = sender.tag;     nsstring *s1 = nslocalizedstring(@"alert_title", nil);     nsstring *s2 = nslocalizedstring(@"alert_body", nil);     nsstring *s3 = nslocalizedstring(@"yes", nil);     nsstring *s4 = nslocalizedstring(@"no", nil);     uialertview *alertview = [[uialertview alloc] initwithtitle:s1                                                         message:s2                                                        delegate:self                                               cancelbuttontitle:s4                                               otherbuttontitles:s3, nil];     [alertview settag:1];     [alertview show];  } 

this method shows alert view calls method, in custom cell class:

- (void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex {     appdelegate *deleg = (appdelegate *)[[uiapplication sharedapplication] delegate];     dboperations *db = [[dboperations alloc] init];     nsstring *alrttitle = [alertview buttontitleatindex:buttonindex];     nsstring *s3 = nslocalizedstring(@"yes", nil);     nsstring *s4 = nslocalizedstring(@"no", nil);     switch (alertview.tag) {         case 1:             //             break;         case 2:             if ([alrttitle isequaltostring:s3]) {                 // db writing , reading                 viewcontrollerwithtable *vc = [[viewcontrollerwithtable alloc] init];                 [vc updateeverything];             } else if ([alrttitle isequaltostring:s4]){                 //              }             break;         case 3:             if ([alrttitle isequaltostring:s3]) {                 //             }             break;         default:             break;     }  } 

in case, updateeverything method don't work.

edit after added more code:

in following lines:

        if ([alrttitle isequaltostring:s3]) {             // db writing , reading             viewcontrollerwithtable *vc = [[viewcontrollerwithtable alloc] init];             [vc updateeverything]; 

you instantiating new view controller altogether has nothing original view controller displayed table view. so, sending update message wrong object.

what need mechanism cell know right controller send message to.

one easy solution using nsnotificationcenter:

  1. the view controller register kind of notification:

    [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(updateeverything:) name:kcellsentupdatemessagenotification object:nil]; 
  2. your cell sends notification, instead of calling message directly:

    [[nsnotificationcenter defaultcenter] postnotificationname:kcellsentupdatemessagenotification object:nil]; 

old answer:

you should call

  [self.tableview reloaddata] 

from updateeverything method implementation. reload table data, updating rows appearance. updateeverything method shall called when tapping on button in row work, obviously.

if not work, please provide more code.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -