UITableView清单问题 [英] UITableView Checklist Problem

查看:46
本文介绍了UITableView清单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个奇怪的问题.我正在使用XCode制作清单程序,并且正在将UITableView与UITableViewCellAccessoryCheckmark一起使用.我可以选择单元格,然后会出现复选标记,但是不知何故,我在下面尚未选择的其他单元格也会出现一个复选标记.有什么想法吗?
这是我的复选标记编码:

I have this bizarre problem. I'm making a checklist program with XCode and I'm using UITableView with UITableViewCellAccessoryCheckmark. I can select cells and the checkmark will appear, but somehow, other cells that I have NOT yet selected below will also have a checkmark appear. Any ideas?
Here's my check mark coding:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
cell = [aTableView cellForRowAtIndexPath: indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark; 

}

我不知道这是否会影响它,但我也实现了此方法:

I don't know if this affects it, but I also implemented this method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CellIdentifier";

// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.accessoryType = UITableViewCellAccessoryNone;
}

// Configure the cell.
if(tableView == Table1){

    switch(indexPath.section){
        case 0:
            cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
            break;
        case 1:
            cell.textLabel.text = [array2 objectAtIndex:indexPath.row];
            break;
        case 2:
            cell.textLabel.text = [array3 objectAtIndex:indexPath.row];
            break;
    }

    //cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
}
if(tableView == Table2){
    cell.textLabel.text = [array4 objectAtIndex:indexPath.row];
}
return cell;

}

谢谢.

推荐答案

每次调用 tableView:cellForRowAtIndexPath:时,设置 cell.accessoryType .否则,当您重复使用一个单元格时,将获得其不是您所期望的而不是附件视图.

Set the cell.accessoryType each time you call tableView:cellForRowAtIndexPath:. Otherwise, when you reuse a cell, you'll get it's accessoryView instead of what you're expecting.

因此,是的,除了通过查看 accessoryType 之外,还需要跟踪通过某些方法选择NSIndexPaths的时间.

So, yeah, you'll need to keep track in when NSIndexPaths are selected by some method other than just looking at the accessoryType.

这篇关于UITableView清单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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