My cell(UITableViewCell) contains a UITextView, and I have customed UIMenuController(Clipboard). Now I need select two or more cells at the same time, so that I can copy the text of them. What should I do?
-
1already asked google? I'm sure there are 100+ answers to this problem. http://stackoverflow.com/questions/6057819/didselectrowatindexpath-selecting-more-than-one-row-at-a-time i.e. – geo Feb 23 '15 at 15:13
2 Answers
Use this line for multiple selection.
self.tableView.allowsMultipleSelection = YES;

- 12,219
- 3
- 25
- 34
Allow multiple selection on your tableview by setting the property
self.tableView.allowsMultipleSelection = YES;
Then, in your didSelectRowAtIndexPath, you could manage a collection of data by storing or removing the UITextView's content based on what is returned by
if (cell.selected) {
// Add to collection
} else {
// Remove from collection
}
In the case that multiple cells are selected when you present your UIMenuController, you could manipulate the menu text to say something like
Copy text from (#) items
and then use your collection to grab the data regardless of which cell they accessed the menu from.
It would be helpful for the user to see some indication of multiple selection. For this you could set the accessoryType on the selected cell to UITableViewCellAccessoryCheckmark.
To deselect the row, set it back to UITableViewCellAccessoryNone.

- 1,613
- 15
- 17