2012-04-25 118 views
1

您能否帮我解答。我需要执行编辑单元格。编辑应该看起来像: 当我按下barButtonItem(导航栏上的右边那个)时,单元格的内容应该稍微向右移动,并且复选框应该出现。用户应该能够选择几个单元格并通过点击相同的导航按钮来提交编辑。 我试过使用标准编辑,但我不知道如何: - 选择多个单元格,然后提交编辑 - 如何将提交操作设置为navButton,而不是红色删除按钮,它出现在每个选中的旁边cell单元格的自定义编辑

+0

http://stackoverflow.com/questions/9101810/custom-uitableviewcell-uitableview-and-allowsmultipleselectionduringediting访问此refence .. – Nit 2012-04-25 13:02:10

回答

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]; } 

希望不能改变,这将帮助你..

+0

谢谢这正是我需要的。你还可以回答当我按下编辑时如何正确布置躺在我的单元格上的自定义视图(标签,按钮,imgView等)? (现在,当我按下编辑时,一些视图正在相对于单元格视图移动)但是我需要这些内容被压缩并且不会移动到可见边界之后。 – Stas 2012-04-25 13:51:57

+0

我现在很忙,有些工作会给你和明天,因为我有一些工作在你的方案。 – Nit 2012-04-25 13:54:03

+0

好的,我会等你的回答.... – Stas 2012-04-26 12:39:25

3

尼特的回答有一个bug。

代码

tableView.multiselectCheckmarkColor = [UIColor blueColor]; 

应该这样写:

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

我想这个对的Xcode 4.5和它的工作。

+0

谢谢,会考虑到它 – Stas 2013-01-19 17:48:58

0

如果它仍然相关,请注意,在iOS 7+上,您可以简单地使用UITableView的tintColor属性 - 这将设置复选标记颜色。