Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 CellForRowatindex路径滞后问题_Iphone_Objective C_Cocoa Touch_Ipad - Fatal编程技术网

Iphone CellForRowatindex路径滞后问题

Iphone CellForRowatindex路径滞后问题,iphone,objective-c,cocoa-touch,ipad,Iphone,Objective C,Cocoa Touch,Ipad,在cellForRowAtIndexPath中,我使用以下内容设置了其中一个UILabel的文本: cell.detail.text = [[poll objectForKey:@"parent"] objectForKey:@"name"]; 但是,当我上下滚动单元格时,这会导致单元格延迟,这只是第一次。在我第一次完成从上到下的滚动后,这是一个滞后的部分,第二次尝试再次从上到下滚动。这并不滞后。为什么会这样?这是我的全部代码: - (UITableViewCell *)tableView:(

在cellForRowAtIndexPath中,我使用以下内容设置了其中一个UILabel的文本:

cell.detail.text = [[poll objectForKey:@"parent"] objectForKey:@"name"];
但是,当我上下滚动单元格时,这会导致单元格延迟,这只是第一次。在我第一次完成从上到下的滚动后,这是一个滞后的部分,第二次尝试再次从上到下滚动。这并不滞后。为什么会这样?这是我的全部代码:

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

    static NSString *CellIdentifier = @"VSCustomCell";
    VSCustomCell * cell = (VSCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray * nib = [[NSBundle mainBundle] loadNibNamed:@"VSCustomCell" owner:self options:nil];
        cell = (VSCustomCell *)[nib objectAtIndex:0];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }


    [cell.main setFont:[UIFont fontWithName:@"cafeta" size:14]];
    [cell.detail setFont:[UIFont fontWithName:@"Bebas" size:8.0]];
    [cell.detail setTextColor:[UIColor grayColor]];

    PFObject * poll;

    [cell.stats setHidden:NO];
    [cell.stats setEnabled:YES];
    [cell.stats addTarget:self action:@selector(stats:) forControlEvents:UIControlEventTouchUpInside];
    [cell.stats setTag:indexPath.row];

    poll = [self.spotsResults objectAtIndex:indexPath.row];
    if (poll){
        cell.main.text = [poll objectForKey:@"question"];
        cell.detail.text = [[poll objectForKey:@"parent"] objectForKey:@"name"];
    }      
    return cell;    
}

稍后滚动变快意味着单元格被重用。这是个好兆头。
所以问题是在第一阶段,即在创建单元部分ifcell==nil{}。再次尝试为单元创建xib别忘了在xib中为单元添加重用标识符。

如果是这样,那么为什么我从上面注释掉字典代码的字典,它会变得很快?另外,在xib中为单元添加重用标识符是什么意思?一些代码会有帮助我还检查了一下,它只创建了4个单元格,其余的都是重用的,当重用它时,它仍然很慢,表中有多少行?如果您确信是objectForKey方法速度慢,那么可能需要从PFObject类发布一些代码。此外,所有setFont和setHidden内容都可以放在if cell==nil语句中,除非在代码的其他地方对其进行更改?意味着它有多少子视图?具有许多UIView的自定义单元格滞后是一个常见问题,如果是这种情况,有几种解决方案。