如何单击按钮将 tableview 单元格附件类型重置为无? [英] How to reset the tableview cells accessorytype to none on a click of a button?

查看:22
本文介绍了如何单击按钮将 tableview 单元格附件类型重置为无?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to code a reset button, so that when I click on that button all the tableview cells' accessory type get set to none.

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

I have a clear concept of how to do it, but I am pretty new to iPhone development so I just need help with what methods to call.

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

The steps I think I need to take: I am iterating through all the rows using a for loop - so I am counting the number of cells (successfully done). My problem is, I have no clue how to check for each of those rows/cells if the accessory type is CheckMark and set it to none.

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

Alternatively, I can set all of my cells to AccessoryNone, but I am already doing some calculations inside the:

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

所以我不知道如何才能做到这一点.

So I am not sure how can I achieve this.

推荐答案

无需先检查 accessoryType 是什么,只需将 UITableViewCellAccessoryNone 分配给它们.这应该适用于您正在尝试执行的操作:

No need to check what the accessoryType is first, just assign UITableViewCellAccessoryNone to all of them. This should work for what you are trying to do:

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

这篇关于如何单击按钮将 tableview 单元格附件类型重置为无?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆