iphone - iOS: retrieving selection state from button created in UITableViewCell -


i have uibutton on custom uitableviewcell (to cells added dynamically), defined on different class mainviewcontroller, customcell class. need method in mainviewcontroller return array if uibuttons selected or not. array should have in n-th index information n-th cell. have written is:

customcell.h:

@interface customcell : uitableviewcell @property (strong, nonatomic) iboutlet uibutton *tickbutton; 

customcell.m:

- (ibaction)tick:(uibutton *)sender {      if ([sender isselected]) {         [sender setimage:[uiimage imagenamed:@"off"] forstate:uicontrolstatenormal];         [sender setselected:no];     } else {         [sender setimage:[uiimage imagenamed:@"on"] forstate:uicontrolstateselected];         [sender setselected:yes];     } } 

mainviewcontroller.m:

-(nsmutablearray*) returntickarray{     nsmutablearray *tickarray = [[nsmutablearray alloc] initwithcapacity:n];     (nsinteger i=0; i<n; i++){         nsindexpath *indexpath = [nsindexpath indexpathforitem:1 insection:0];     customcell *cell = (customcell *) [self.itemtable cellforrowatindexpath:indexpath];         if ([cell.tickbutton isselected]){             a=[nsnumber numberwithint:1];         }         else {             a=[nsnumber numberwithint:0];         };         [tickarray addobject:a];     }      return tickarray;  } 

i have tried instead of using button selected state create public nsnumber property , having uibutton make alternate between 1 , 0, , "asking it" on mainviewcontroller, hasn't worked.

you creating [nsindexpath indexpathforitem:1 insection:0]; 1 row. should replace 'i' using in loop.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -