5

我正在尝试编写一个重置按钮,以便当我单击该按钮时,所有 tableview 单元格的附件类型都设置为none.

我对如何做到这一点有一个清晰的概念,但我对 iPhone 开发还很陌生,所以我只需要关于调用什么方法的帮助。

我认为我需要采取的步骤:我正在使用 for 循环遍历所有行 - 所以我正在计算单元格的数量(成功完成)。我的问题是,如果附件类型是 CheckMark 并将其设置为none.

或者,我可以将所有单元格设置为AccessoryNone,但我已经在其中进行了一些计算:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

所以我不确定如何实现这一目标。

4

2 回答 2

12

无需检查accessoryType第一个是什么,只需分配UITableViewCellAccessoryNone给所有这些。这应该适用于您正在尝试做的事情:

// replace clickedResetButton with your action handler method for that button
- (IBAction)clickedResetButton:(id)sender {
    for (int section = 0, sectionCount = self.tableView.numberOfSections; section < sectionCount; ++section) {
        for (int row = 0, rowCount = [self.tableView numberOfRowsInSection:section]; row < rowCount; ++row) {
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.accessoryView = nill;
        }
    }
}
于 2011-11-20T23:05:45.143 回答
2

斯威夫特 3.1

func resetAccessoryType(){
    for section in 0..<self.tableView.numberOfSections{
        for row in 0..<self.tableView.numberOfRows(inSection: section){
            let cell = self.tableView.cellForRow(at: IndexPath(row: row, section: section))
            cell?.accessoryType = .none
        }
    }
}
于 2017-08-08T13:30:21.220 回答