Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableView在滚动时移动单元格内容_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

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

Iphone UITableView在滚动时移动单元格内容,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我在这里看到了与此相关的其他问题,但我有他们的解决方案,当我滚动时,事情仍然在移动 基本上,我有一个数据表,我希望第一行(也是唯一的第一行)有一个UITableViewCellAccessoryDisclosureIndicator。问题是,当我四处滚动时,指示器会复制、删除并移动到其他单元格。这是我的密码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)in

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

基本上,我有一个数据表,我希望第一行(也是唯一的第一行)有一个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行时更改屏幕。。不管我滚动到哪里,除了第一个单元格外,没有任何单元格触发。因此,检查似乎总是正确的,而CellForRowatineXpath中的检查不是…

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

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

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

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

哦,哇。。我想当你重新使用这些细胞的时候,所有的信息都被丢弃了。它真的保留了吗?这就是问题所在。谢谢你,伙计。我从来没有想到会发生这种情况。当我第一次开始使用UITableview时,我也很困惑。我想tableview无法知道单元格在其“原始”状态下的外观,因此它们只提供缓存的内容并让您处理它!哦,哇。。我想当你重新使用这些细胞的时候,所有的信息都被丢弃了。它真的保留了吗?这就是问题所在。谢谢你,伙计。我从来没有想到会发生这种情况。当我第一次开始使用UITableview时,我也很困惑。我想tableview无法知道单元格在其“原始”状态下的外观,因此它们只提供缓存的内容并让您处理它!