开发者

cellForRowAtIndexPath lagging issues

开发者 https://www.devze.com 2023-04-12 05:33 出处:网络
Inside my cellForRowAtIndexPath I set a text of one of my UILabel\'s with the following: cell.detail.text = [[poll objectForKey:@\"parent\"] objectForKey:@\"name\"];

Inside my cellForRowAtIndexPath I set a text of one of my UILabel's with the following:

cell.detail.text = [[poll objectForKey:@"parent"] objectForKey:@"name"];

However, this causes the cell to lag as I scroll up and down the cell and this is only for the first time. After I finish scrolling from the top to the bottom for the very first time(this is the laggy part) and try to do it again for the second time (scroll from top to bottom). This doesn't lag. Why is this? Here is my full code:

- (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 s开发者_开发问答etFont:[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;    
}


Scrolling becomes fast later means cells are getting reused. Which is good sign. So the problem is in 1st phase, i.e in creating cell section if(cell==nil){}. Try creating the xib for cell again (don't forget to add reuse identifier for cell in xib) .

0

精彩评论

暂无评论...
验证码 换一张
取 消