【发布时间】:2016-03-02 10:45:24
【问题描述】:
我想问,我如何转发到编辑模式,在那里我可以选择多行,就像在消息应用程序中一样,当你点击右上角的“选择”按钮时,你可以通过点击圆圈来选择多条消息.
像这样:
我搜索了很多,真的,但找不到任何东西。谁能帮我?一些建议
【问题讨论】:
标签: ios swift uitableview multipleselection
我想问,我如何转发到编辑模式,在那里我可以选择多行,就像在消息应用程序中一样,当你点击右上角的“选择”按钮时,你可以通过点击圆圈来选择多条消息.
像这样:
我搜索了很多,真的,但找不到任何东西。谁能帮我?一些建议
【问题讨论】:
标签: ios swift uitableview multipleselection
设置
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"];
}
}
也让它正常工作..
【讨论】: