自定义编辑单元格

时间:2012-04-25 12:56:50

标签: iphone objective-c uitableview edit cells

你能帮我吗?我需要执行编辑单元格。编辑应如下所示: 当我按下barButtonItem(导航栏上的右边)时,单元格的内容应该稍微向右移动,并且应该出现复选框。用户应该能够选择多个单元格并通过单击相同的navButton来提交编辑。 我试过使用标准编辑,但我无法弄清楚如何: - 选择多个单元格,然后才进行编辑 - 如何将提交操作设置为navButton,但不设置为每个选定单元格旁边显示的红色删除按钮

3 个答案:

答案 0 :(得分:3)

多选被视为编辑风格之一。因此,要使单元格可多选,请在UITableViewDelegate中实现:

-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
  ...
  return 3;
}

这里的“3”表示多选。结果是这样的:

enter image description here

要获取所选行,请调用

-indexPathsForSelectedRows method on the table view.
NSArray* selectedRows = [tableView indexPathsForSelectedRows];

如果您不喜欢红色复选标记,则可以使用未记录的multiselectCheckmarkColor属性进行更改。不幸的是,它必须应用于整个表格。

tableView.multiselectCheckmarkColor = [UIColor blueColor];

除非您进行子类化或分类

,否则无法更改浅蓝色背景颜色
UITableViewCell and override the -_multiselectBackgroundColor method, like this:
-(UIColor*)_multiselectBackgroundColor { return [UIColor yellowColor]; }

希望,这会对你有帮助..

答案 1 :(得分:3)

Nit的答案有一个错误。

代码

tableView.multiselectCheckmarkColor = [UIColor blueColor];

应该写成这样:

[tableView setValue:[UIColor blueColor] forKey:@"multiselectCheckmarkColor"];

我在Xcode 4.5上试过这个并且它有效。

答案 2 :(得分:0)

如果它仍然相关,请注意在iOS 7+上您只需使用UITableView的tintColor属性 - 这会设置复选标记颜色。

相关问题