如何使用UITableViewCellAccessoryCheckmark取消选中所有行 [英] How to uncheck all rows using UITableViewCellAccessoryCheckmark

查看:146
本文介绍了如何使用UITableViewCellAccessoryCheckmark取消选中所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView ,每行包含一个使用 UITableViewCellAccessoryCheckmark 的复选框。我无法弄清楚如何使用 didSelectRowAtIndexPath 方法取消选中所有复选框。

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

UITableViewCell * oldCell;

int count = [self.myTableRowNamesArray count];

for(NSUInteger i = 0; i< count; ++ i){
//取消选中所有复选框
//当然这不工作
//因为我是一个整数,而且INDEXPATH是一个指针
FOO:oldCell = [myTableView cellForRowAtIndexPath:(int)i];
// GOOD CODE:
oldCell = [penanceOptionsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
oldCell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell * newCell = [myTableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
}


解决方案

是的, cellForRowAtIndexPath:使用 NSIndexPath 而不是整数,因此使用



<$ p $生成indexpath p> indexPathForRow:inSection:

如果你使用一个部分然后你的循环很好,只是在行中传递i,在段中传递0。


I've got a UITableView with each row containing a checkbox using UITableViewCellAccessoryCheckmark. I can't figure out how to uncheck all the checkboxes using the didSelectRowAtIndexPath method.

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

    UITableViewCell *oldCell;

    int count = [self.myTableRowNamesArray count];

    for (NSUInteger i = 0; i < count; ++i) {                                
        // Uncheck all checkboxes
        // OF COURSE THIS DOESN'T WORK
        // BECAUSE i IS AN INTEGER AND INDEXPATH IS A POINTER
        FOO: oldCell = [myTableView cellForRowAtIndexPath:(int)i];
        // GOOD CODE:
        oldCell = [penanceOptionsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        oldCell.accessoryType = UITableViewCellAccessoryNone;
    }
    UITableViewCell *newCell = [myTableView cellForRowAtIndexPath:indexPath];
    newCell.accessoryType = UITableViewCellAccessoryCheckmark;
}

解决方案

Yes, cellForRowAtIndexPath: uses NSIndexPath instead of integer so make indexpath by using

indexPathForRow:inSection:

if you are using one section then your loop is fine just pass i in row and 0 for section.

这篇关于如何使用UITableViewCellAccessoryCheckmark取消选中所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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