如何通过单击按钮将tableview cells accessorytype重置为none?

sub*_*ahl 5 uitableview nsindexpath

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

我有一个明确的概念,如何做到这一点,但我是iPhone开发的新手,所以我只需要帮助调用什么方法.

我认为我需要采取的步骤:我使用for循环迭代所有行 - 所以我计算单元格数量(成功完成).我的问题是,如果附件类型是CheckMark并将其设置为,我不知道如何检查每个行/单元格none.

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

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

cho*_*own 11

无需检查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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)