1

我在这里看到了与此相关的其他问题,但我有他们的解决方案,当我滚动时,事情仍然会发生变化。

基本上,我有一个数据表,我希望第一行也是唯一的第一行有一个 UITableViewCellAccessoryDisclosureIndicator。问题是,当我滚动时,指示器会复制、删除并移动到其他单元格。这是我的代码..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }    

    if(indexPath.row == 0) {      
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;           
    }

    cell.textLabel.text = [tabledata objectAtIndex:indexPath.row];

    return cell;
}

问题出在 indexPath.row 变量上。它以某种方式在不是第一个的其他单元格中返回 0(在显示单元格时)。但是......数据总是来自我的数组(这意味着值必须是正确的)并且在我的

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

方法,我只希望在单击第 0 行时更改屏幕.. 无论我滚动到哪里,除了第一个单元格之外,没有单元格触发。所以看起来那个检查总是正确的,而 cellForRowAtIndexPath 里面的那个不是......

4

1 回答 1

1

最有可能的是,您正在重新使用已经拥有该accessoryType集合的单元格。您需要将其显式设置为不显示在不应显示的单元格上。

if(indexPath.row == 0){      
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;       
} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}
于 2012-06-15T19:13:56.070 回答