Reputation: 9935
Could you please help me. I need to perform editing cells. The editing should look like: when I press a barButtonItem (the right one on the nav bar) the content of cells should slightly move to the right and checkboxes should appear. The user should be able to select several cells and commit editing by clicking on the same navButton. I've tried to use standard editing but I can't figure out how: - to select multiple cells and only then commit editing - how to set commit action to navButton but not to red delete button which appears next to each selected cell
Upvotes: 1
Views: 1767
Reputation: 21
If it's still relevant, note that on iOS 7+ you can simply use the tintColor property of the UITableView - this sets the checkmark colour.
Upvotes: 0
Reputation: 1143
Nit's answer has a bug.
The code
tableView.multiselectCheckmarkColor = [UIColor blueColor];
should be written like this:
[tableView setValue:[UIColor blueColor] forKey:@"multiselectCheckmarkColor"];
I tried this on Xcode 4.5 and it worked.
Upvotes: 3
Reputation: 7461
Multi-selection is regarded as one of the editing style. Therefore, to make a cell multi-selectable, implement this in your UITableViewDelegate:
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
...
return 3;
}
The "3" here means multiselection. The result is like this:
To get the selected rows, call the
-indexPathsForSelectedRows method on the table view.
NSArray* selectedRows = [tableView indexPathsForSelectedRows];
If you dislike the red check mark, you can use the undocumented multiselectCheckmarkColor property to change it. Unfortunately, it has to be applied on the whole table.
tableView.multiselectCheckmarkColor = [UIColor blueColor];
The light blue background color cannot be changed unless you subclass or categorize
UITableViewCell and override the -_multiselectBackgroundColor method, like this:
-(UIColor*)_multiselectBackgroundColor { return [UIColor yellowColor]; }
Hope, this will help you..
Upvotes: 3