繁体   English   中英

UITableView在滚动时会移动单元格内容

[英]UITableView moves cell contents around when scrolling

我在这里看到了与此有关的其他问题,但是我已经有了相应的解决方案,并且当我滚动时,一切仍然在进行。

基本上,我有一个数据表,我希望第一行,也只有第一行具有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内部不正确的情况下检查总是正确的...

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM