我真的陷入僵局了。我有一个有and标签和图片的桌面视图。使用HJcache库下载图像。一切都很好,但是非常非常慢,下面是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *currentCellId = @"currentCell";
NSUInteger currentRow = [indexPath row];
HJManagedImageV* currentImage;
UILabel *textLabel;
UIImageView *onlineStatusView;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:currentCellId];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:currentCellId];
currentImage = [[HJManagedImageV alloc] initWithFrame:CGRectMake(2,2,40,40)];
[currentImage setTag:999];
[cell addSubview:currentImage];
textLabel = [[UILabel alloc] initWithFrame:CGRectMake(50.0f, 2.0f, cell.frame.size.width - 50.0f, cell.frame.size.height-4.0f)];
[textLabel setTag:777];
[textLabel setFont:[UIFont boldSystemFontOfSize:12.0f]];
[cell addSubview:textLabel];
if ([[[dataArray objectAtIndex:currentRow] objectForKey:@"online"] integerValue] == 1){
onlineStatusView = [[UIImageView alloc] initWithFrame:CGRectMake(cell.frame.size.width-15.0f,
cell.frame.size.height/2,
10.0f,
10.0f)];
[onlineStatusView setTag:888];
[cell addSubview:onlineStatusView];
}
} else{
onlineStatusView = (UIImageView *)[cell viewWithTag:888];
textLabel = (UILabel *)[cell viewWithTag:777];
currentImage = (HJManagedImageV*)[cell viewWithTag:999];
[currentImage clear];
}
currentImage.url = [NSURL URLWithString:[[dataArray objectAtIndex:currentRow] objectForKey:@"image"]];
[cache manage:currentImage];
[currentImage setOpaque:YES];
currentImage = nil;
NSString *nameString = [NSString stringWithFormat:@"%@ %@",
[[dataArray objectAtIndex:currentRow] objectForKey:@"firstName"],
[[dataArray objectAtIndex:currentRow] objectForKey:@"lastName"]];
[textLabel setText:nameString];
[textLabel setOpaque:YES];
textLabel = nil;
if (onlineStatusView){
[onlineStatusView setImage:[UIImage imageNamed:@"Online@2x.png"]];
[onlineStatusView setOpaque:YES];
onlineStatusView = nil;
}
return cell;}
一切看起来都很好,我删除了所有不必要的分配,缓存的图像,但都没有用。我哪里做错了?
现在我已经有大约200行了,但是bug在20行的时候就开始了,我想我的错误真的很愚蠢。
发布于 2012-03-12 01:34:31
这里有几个问题:
我不知道你正在使用的库,所以不能对此发表评论。
发布于 2012-03-12 02:11:16
在缓存中插入一些NSLog():管理调用以查看它们真正持续了多长时间。不要担心您的200行,cellForRowAtIndexPath只对可见的行调用。
https://stackoverflow.com/questions/9657039
复制相似问题