开发者

UITableViewCell is getting allocated again and again while scrolling

If a UITableViewCell has been allocated ,while scrolling, it should not be reallocated. It is however. How can I prevent tha开发者_StackOverflowt from happening?


If you want to reuse the cell then code in cellForRowAtIndexPath some thing like that

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil) 
    {
     CGRect CellFrame;

        CGRect nameLabelFrame; 

        CGRect countLabelFrame;

        CellFrame = CGRectMake(0, 0, 320, 80);

        nameLabelFrame = CGRectMake(10, 10, 270, 50);
        countLabelFrame = CGRectMake(10, 58, 270, 12);


        cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:CellIdentifier] autorelease];
        UILabel *lblTemp;
        //UIImageView *imgTemp;

        lblTemp = [[UILabel alloc] initWithFrame:nameLabelFrame];
        lblTemp.tag = 1;
        [cell.contentView addSubview:lblTemp];
        [lblTemp release];



        lblTemp = [[UILabel alloc] initWithFrame:countLabelFrame];
        lblTemp.tag = 3;
        [cell.contentView addSubview:lblTemp];
        [lblTemp release];

}

//And outside of if condition access these labels by this

    //UIConstruction
        UILabel *nameLabel = (UILabel *)[cell viewWithTag:1];

        UILabel *countLabel = (UILabel *)[cell viewWithTag:3];

and use these labels or controls what you want outside this if condition

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜