如何通过单击ios中的全选按钮选择tableview单元格中的所有复选框按钮

时间:2015-12-24 07:51:55

标签: ios uitableview checkbox uibutton togglebutton

您好我正在使用tableview单元格的复选功能,因为我在tableview单元格中使用了一个按钮,当我点击导航栏按钮时我在导航栏中的另一个按钮我要选择所有带有其他图像的按钮,如checkBox和执行个人每个表视图单元格按钮的复选框任何帮助提前感谢

2 个答案:

答案 0 :(得分:1)

我可以建议两种方法,检查一下你可行的方法:)

不要将图像用于细胞,否则会不必要地增加细胞的重量。您可以使用accessoryView。

方法1:存储用户选择的单元格的所有索引路径。 创建一个NSMutableArray来保存索引路径,让我们将其称为SelectedIndexPathArray。

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
           if([SelectedIndexPathArray containsObject: indexPath]){
                 cell.accessoryType = UITableViewCellAccessoryCheckmark;
           }
           else{
                cell.accessoryType = UITableViewCellAccessoryNone;
           }
       return cell;
}

现在,当用户点击选择所有按钮时,将tableview的所有索引路径添加到数组:) 您可以轻松地执行此操作,您也可以获得代码片段:)

当用户点击单个单元格时,您所要做的就是:)

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        if([SelectedIndexPathArray containsObject: indexPath]){
                     cell.accessoryType = UITableViewCellAccessoryNone;
                     [SelectedIndexPathArray removeObject:indexpath];
               }
               else{
                    cell.accessoryType = UITableViewCellAccessoryCheckmark;
                    [SelectedIndexPathArray addObject:indexpath];
               }
}

多数民众议员:) 方法2:它是一个不同的方法,如果这种方法对你不起作用,建议:)知道:)

快乐编码

答案 1 :(得分:0)

1)在该.m文件中取一个全局 bool isAllSelected

2)在naviagtion栏按钮上单击将该bool设为true并重新加载tableview

3)并在cellForRowAtIndexMethod中创建一个条件

{{1}}