Reputation: 561
I'm really in deadlock. I've got a tableview with uilabels and images. Images downloads with HJcache library. All works fine, but very very slow, here is my code:
- (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:@"[email protected]"]];
[onlineStatusView setOpaque:YES];
onlineStatusView = nil;
}
return cell;
}
All looks pretty good, I removed all unnecessary allocations, cached images, but all without avail. What I'm doing wrong?
ps now i've got around 200 rows, but bugs starts when it was 20. I guess my mistake really stupid.
Upvotes: 0
Views: 325
Reputation: 5722
Insert some NSLog() around your cache:manage calls to see how long they really last. Don't worry about your 200 rows, cellForRowAtIndexPath is only called for the visible rows.
Upvotes: 0
Reputation: 119272
Couple of issues here:
I don't know about the library you are using so can't comment on that.
Upvotes: 1