【发布时间】:2012-02-06 11:39:24
【问题描述】:
这让我在一天中的大部分时间都快疯了。
我有一个带有 UIImageViews 的 UITableView。这些图像视图在 tableview 的 cellForRow 函数中加载本地保存的 PNG 文件,这可以正常工作,只是当带有图像的单元格滚动到视线中时,tableview 将停止滚动几分之一秒。我已经在 StackOverflow 和谷歌上搜索了答案,但我的回答很短 - 所以任何帮助都将不胜感激。
这是我的 CellForRow 函数代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if([currSection isEqualToString:@"composer"]){
MySlide *s = [slidesArray objectAtIndex:indexPath.row];
cell.textLabel.hidden = YES;
UIImageView *whiteView = [[UIImageView alloc] initWithFrame:CGRectMake((projectsTable.frame.size.width/2)-150, 4, 204.8, 153.6)];
if([s.slideImage isEqualToString:@""] || s.slideImage == nil){
//no custom image in this cell - go with default background image
whiteView.image = [UIImage imageNamed:@"cellback2.png"];
whiteView.backgroundColor = [UIColor whiteColor];
}else{
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
NSData *data = [[NSData alloc] initWithContentsOfFile:s.slideImage];
UIImage *im = [[UIImage alloc] initWithData:data];
whiteView.image = im;
whiteView.image = [self imageWithImage:whiteView.image CovertToSize:CGSizeMake(204.8,153.6)];
whiteView.backgroundColor = [UIColor whiteColor];
}
[cell.contentView addSubview:whiteView];
[whiteView release];
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
【问题讨论】:
-
发生这种情况的原因是每次创建新单元格、分配图像视图、格式化和添加..
-
我忘了提到我已经尝试在 if(cell == nil) 语句中设置 whiteBack,但是在向滑动对象。请给我一个简单的例子来说明你将如何解决这个问题?
-
检查我的回答代码,我已经更新了..
标签: iphone performance uitableview uiimageview