iphone - Can't select UITableViewCell when TableView setEditing is set -
i want able select multiple rows default mail app shown below:
i have button called edit calls
[self.mytableview setediting:yes animated:yes]
the edit button shows circles on left of cells mail app shown above. however, when select 1 of rows, nothing happens. red checkmark not appear in circle expect. why isn't red checkmark appearing?
#pragma mark - uitableviewdatasource methods - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"myidentifier"]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:@"myidentifier"]; } cell.textlabel.text = @"hey"; return cell; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return 3; } #pragma mark - uitableviewdelegate methods - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [tableview deselectrowatindexpath:indexpath animated:yes]; } - (uitableviewcelleditingstyle)tableview:(uitableview *)tableview editingstyleforrowatindexpath:(nsindexpath *)indexpath { return 3; } #pragma mark - private methods - (ibaction)editbuttontapped:(id)sender { if (self.mytableview.editing) { [self.mytableview setediting:no animated:yes]; } else { [self.mytableview setediting:yes animated:yes]; } }
you have explicitly set selection enabled during editing mode:
[self.tableview setallowsselectionduringediting:yes];
or
[self.tableview setallowsmultipleselectionduringediting:yes];
according docs: these properties set no
default.
if value of property yes , users can select rows during editing. default value no. if want restrict selection of cells regardless of mode, use allowsselection.
additionally, following snippet of code may causing problems selection because deselects row it's been selected.
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [tableview deselectrowatindexpath:indexpath animated:yes]; }
Comments
Post a Comment