问题
I want to ask, how can I forward to edit mode, where I can to select multiple rows, as in Messages app, when you click on top right button "Select", when you can choose multiple messages by tapping on circles.
Like this:
I searched a lot, really, but couldn't find anything. Can anyone help me? Some advices
回答1:
Set
tableView.allowsMultipleSelectionDuringEditing = true
Screenshot
Demo code
class TableviewController:UITableViewController{
override func viewDidLoad() {
super.viewDidLoad()
tableView.allowsMultipleSelectionDuringEditing = true
tableView.setEditing(true, animated: false)
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = "\(indexPath.row)"
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
}
回答2:
If you're using Storyboards do this:
回答3:
NSMutableArray *selected;
decleare it in you viewcontroller.h file..
selected =[[NSMutableArray alloc]init];
for (int i=0; i<[YOUR_ARRAY count]; i++) // Number of Rows count
{
[selected addObject:@"NO"];
}
add same number of "NO" in selected array using above code for that you had to replace YOUR_ARRAY with your data array that you show in table.
if(![[selected objectAtIndex:indexPath.row] isEqualToString:@"NO"])
{
cell.accessoryType=UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType=UITableViewCellAccessoryNone;
}
put above code in your -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[selected replaceObjectAtIndex:path.row withObject:@"YES"];
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
[selected replaceObjectAtIndex:path.row withObject:@"NO"];
}
}
also put this to work correctly..
来源:https://stackoverflow.com/questions/33970807/how-to-select-multiple-rows-in-uitableview-in-edit-mode