I have a UITableView that is loading a list of Albums from an MPMediaQuery. Everything had been working fine, until I noticed that an album with a non-square album art was pushing the label-text of a built-in cell view to the right. Noticing this was my downfall, as during the process I also noticed that scrolling was less than smooth.
I went to make a cell from a nib, which resolved the positioning issues, but performance still suffered. At this point, I started doing copious amounts of research and trying everything in my ability to implement.
- first was cell from nib with an imageview, and two labels
- to correct for the weird scaling in the imageview, I added the imageview inside a uiview to crop it (no real hit on performance).
- loaded the image without any post-processing, still jittery performance.
- implemented the cell in -(void)drawRect (like the example in Apple's TableViewSuite example #5), passing the image from the tableview. This was only loading the first ~8 images initially, and performance was only slightly stuttered.
- I then set [myCell setNeedsDisplay] to have it redraw the cell so all the other images would display correctly, and performance went back down. I also tried only redrawing the portion with the image with no change.
- this method with only one static image yielded perfect performance.
I have made sure all the normal things like cellIdentifier etc are correct, and, if the cell view only has text it scrolls perfectly.
Below find an implementation of the tableviewcell using one of the default cell views to illustrate how I am currently grabbing images for the cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Cell initizalation
static NSString *CellIdent = @"CellIdent";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdent];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdent];
}
cell.imageView.image = [[[[albumList
objectAtIndex:indexPath.section]objectAtIndex:indexPath.row] valueForProperty:MPMediaItemPropertyArtwork]imageWithSize:CGSizeMake(0,56)];
//it seems to scale with a sharper image if CGSizeMake has a value, rather than
//CGSizeZero. It doesn't actually do any scaling at this point, which I initially thought
//it would, but the results were more what I wanted so...
return cell;
}
In Apple's ipod app, the list of Albums with art scrolls like silk, so obviously, I am missing something.