Why don't checkboxes appear when UITableView.allowsMultipleSelection is enabled?

I have a UITableView in an iOS5.1 application where I installed

self.tableView.allowsMultipleSelection=YES; 

Apple's documentation states: "When the value of this property is YES, a check mark is placed next to each line used. Clicking on the line again deletes the check mark.".

I can select multiple lines as the background is set to blue. However, no checkmarks are displayed. Is it necessary to check the box as shown below in the didSelectRowAtIndexPath file because I use custom UITableViewCells?

 cell.accessoryType = UITableViewCellAccessoryCheckmark; 
+8
objective-c uitableview
source share
2 answers

I manually checkmark my subclasses of uitableviewcell. You will need to manually execute the UITableViewCellAccessoryCheckmark in the didSelectRowAtIndexPath file and save the track which one is selected. I would recommend something like this:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [tableview cellAtIndex:indexPath]; if(cell.accessoryType == UITableViewCellAccessoryCheckmark) cell.accessoryType = UITableViewCellAccessoryCheckmark; else cell.accessoryType = UITableViewCellAccessoryNone; } 

Note: I have not tested this, but should give you the basic idea. Let me know if you have any questions. Have you tried to use the standard uitableviewcell and see if this mark was? I would not think that a subclass would have a problem if you do not change in the subclass.

+5
source share

Another option is to use tableView: didDeselectRowAtIndexPath: in addition to tableView: didSelectRowAtIndexPath:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

{

 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryCheckmark; 

}

 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryNone; 

}

+1
source share

All Articles