这个问题困扰两个星期了,求大神帮忙解决。我自己写了一个cell继承了UITableViewCell,然后在cell里面加了贴图和标签,以达到项目需要的效果。问题来了在真机测试的时候,tableView往下拖,刷新新的cell会卡。而且调试发现,不停的上拉下拉。内存会不断增加。上代码- (ChatCustomCell1 *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *identifier = @"tableViewIdentifier";
    ChatCustomCell1 *cell = [tableView dequeueReusableCellWithIdentifier: identifier];
    if(cell == nil)
    {
        [self.cellNib instantiateWithOwner:self options:nil];
        cell = tmpCell;
        self.tmpCell = nil;
    }
    NSInteger row = [indexPath row];
    ChatMessage *chatMessage = (ChatMessage *)[chatMessageArray objectAtIndex:row];
    cell.messageLable.text = chatMessage.message;
    
    // 设置cell
    if (chatMessage.fromMyself)
    {
        UIImage *image = [UIImage imageNamed:@"online.png"];
        cell.leftFaceImageView.image = image;
        [image release];
        [cell.leftTimeLable setText:chatMessage.messageTime];
        UIImage *image1 = [UIImage imageNamed:@"bubule2"];
        cell.messageBackImage.image = image1;
        [image1 release];
        AppDelegate *myApp = [[UIApplication sharedApplication] delegate];
        cell.leftNameLable.text = myApp.loginName;
    }
    else
    {
        UIImage *image = [UIImage imageNamed:@"online.png"];
        cell.rigthFaceImageView.image = image;
        [image release];
        
        cell.rightTimeLable.text = chatMessage.messageTime;
        UIImage *image1 = [UIImage imageNamed:@"bubule1"];
        cell.messageBackImage.image = image1;
        [image1 release];
        cell.rightNameLable.text = chatMessage.senderName;
    }
    cell.messageLable.textAlignment = NSTextAlignmentCenter;
    cell.messageLable.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
    [cell.messageLable setNumberOfLines:0];
    return cell;
}
UItableView内存不断增加

解决方案 »

  1.   

    你可以看下提升Tableview性能方面的知识,加载数据可以绑定到你子类化cell的那个类中去
      

  2.   

    self .cellnib  感觉每次生成并没有  释放      你去看下吧
      

  3.   

    self.tmpCell 不需要设全局变量,因为每次生成的cell你都赋值给self.tmpCell,而self.tmpCell一直都没有释放,只有本类release了cell才会释放。不需要设置全局变量,有方法可以拿到制定的cell.
      

  4.   

    刚才仔细看了下你的代码,你试试这个方法static BOOL register = NO
    if(!register) 
    {
     NSBundle *bundle = [NSBundle bundleForClass:[ChatCustomCell1 class]];
     UINib *cellNib = [UINib nibWithNibName:@"ChatCustomCell1" forBundle: bundle];
     [tableView registerNib:cellNib forCellReuseIdentifier:identifier];
    }
    ChatCustomCell1 *cell = [tableView dequeueReusableCellWithIdentifier: identifier];