这个问题困扰两个星期了,求大神帮忙解决。我自己写了一个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卡内存不断增加
{
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卡内存不断增加
解决方案 »
- IOS 在Storyboard下怎么手动来添加控件
- UIScrollView上面创建了许多按钮之后滚动不流畅的问题
- 【UIScrollView 设置pagingEnabed后滑动的问题??
- 取图片相关
- Objective-C语言方法?
- Buddle ID是什么
- 华为C8825D刷成砖机了,粉屏
- iOS 如何把app里的音频文件写入到本地
- 苹果上线被驳回,Guideline 5.2.1 - Legal - Intellectual Property
- 菜鸟求教,如何让ScrollView填满整个屏幕?
- 为什么字符串压缩之后不是zip包
- 我使用Xcode4.6.3制作应用,教程上说制作好按钮后在按钮上点鼠标右键就可以设置事件了,但为什么我点了后没有反映啊?请高手解答。
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];