我想问一下,当我点击右上角的按钮“选择”时,我可以转发到编辑模式,我可以选择多行,例如在消息应用中,当您可以通过点击圆圈选择多个消息时。
像这样:
我搜索了很多,真的,但找不到任何东西。谁能帮我?一些建议
组
tableView.allowsMultipleSelectionDuringEditing = true
截图
演示代码
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
}
}
NSMutableArray *selected;
在viewcontroller.h文件中声明它..
selected =[[NSMutableArray alloc]init];
for (int i=0; i<[YOUR_ARRAY count]; i++) // Number of Rows count
{
[selected addObject:@"NO"];
}
使用上面的代码在所选数组中添加相同数量的“NO”,因为您必须将YOUR_ARRAY替换为您在表中显示的数据数组。
if(![[selected objectAtIndex:indexPath.row] isEqualToString:@"NO"])
{
cell.accessoryType=UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType=UITableViewCellAccessoryNone;
}
把上面的代码放在你的 - (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"];
}
}
也让这个正常工作..