objective c - UITableView accessoryType disappears in last half of UITableView -
i have ipad app (xcode 4.6, arc, storyboards, ios 6.2.3). have uipopover uitableview has 21 rows in it. can set accessorytype in of rows randomly, in first 12 rows accessorytype setting (checkmark) persist can examined in method , processed. don't see difference between first 12 rows , last 9 rows. uitableview scrollable, rows after 11th row, have scroll bottom
here code set accessorytype:
#pragma mark didselectrowatindexpath
- (void) tableview:(uitableview *) tableview didselectrowatindexpath: (nsindexpath *)indexpath {
// cell selected uitableviewcell *thecell = [tableview cellforrowatindexpath:indexpath]; if(thecell.accessorytype != uitableviewcellaccessorycheckmark) thecell.accessorytype = uitableviewcellaccessorycheckmark; else thecell.accessorytype = uitableviewcellaccessorynone; }
here code check accessorytype , process it:
-(void) moveservices { // (moves checked tableviewrows services tableview) nsmutablestring *result = [nsmutablestring string]; (int = 0; < [servicesarray count]; i++) { nsindexpath *path = [nsindexpath indexpathforrow:i insection:0]; [tvservices scrolltorowatindexpath:path atscrollposition:uitableviewscrollpositionmiddle animated:no]; uitableviewcell *cell = [tvservices cellforrowatindexpath:path]; if (cell.accessorytype == uitableviewcellaccessorycheckmark) { [result appendformat:@"%@, ",cell.textlabel.text]; nslog(@"\n\ni: %d\ncell.accessorytype: %d\ncell.textlabel: %@",i,cell.accessorytype, cell.textlabel); } } if (result.length > 2) { // move text box in main menu storeservices =[result substringtoindex:[result length] - 2]; }
}
it looks you're mixing notion of "data source" , contents of cells in table. don't -- keep data source (whether or not particular row in table should display checkmark based on program logic) separate settings of particular cells (whether or not particular cell displays checkmark). in cellforrowatindexpath
, build cell match data source's current settings. reason uitableview reuses cell instances based on rows visible on-screen (and it's mvc design).
in case should keep nsmutablearray
property in class records settings entire table, , use value array in cellforrowatindexpath
set particular cell. other "business logic" methods in controller use array property query model state instead of cell settings (which part of view , should independent data model).
Comments
Post a Comment