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

时间:2012-06-15 19:09:31

标签: iphone objective-c ios xcode

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

基本上,我有一个数据表,我希望第一行和第一行都有一个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中的那个不是......

1 个答案:

答案 0 :(得分:1)

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

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