iOS5: UITableView poor scrolling performance

Go To StackoverFlow.com

4

First of all I am getting memory leak while scrolling tableview out of bounds. The same issue as here.

Also, my scroll is fast enough but it 'kind of trembles' while I scroll it. The cells are reusable.

Code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    Country *country=[[self.items objectAtIndex:[indexPath section]] objectAtIndex:[indexPath row]];
    CountryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.imageView.image=[UIImage imageNamed:country.countryFlag];
    cell.countryName.text=country.countryName;
    cell.currencyCode.text=country.code;
    cell.currencyOriginalName.text=country.originalUnitName;

    return cell;
}

App: iOS 5, ARC, Storyboard.

What can be the real reason of this tableView behavior and how to fix it ?

2012-04-04 23:01
by NCFUSN
Have you set the cell ID of your CountryCell nib to "Cell"? Have you registered the nib with registerNib:forCellReuseIdentifier: - JiaYow 2012-04-04 23:19
are the cells using custom height or some other delegate method that has known performance issues - Jesse Naugher 2012-04-05 01:45
How big is the country.countryFlag image? Where is that image coming from - sosborn 2012-04-05 02:32
@ Jesse Naugher No,cells are standard. @sosborn flag image is 100x100 and coming from images folder in sandbox - NCFUSN 2012-04-05 03:47
Is this really your code, because I can not see where you are creating CountryCell in the first place. You should be checking that cell is not nil and creating a new CountryCell if it is. You should at the very least have to create two cell before cell will no longer return nil (2 if each cell is as big as your table) - Nathan Day 2012-04-05 03:54
CountryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; It's obvious that I am using subClass called CountryCell. Cell has standard height. Nothing extraordinary in it. This approach worked fine before - NCFUSN 2012-04-05 04:58
@Nathan Day Yes. And subclass too - NCFUSN 2012-04-05 05:01
@NathanDay - with storyboards, dequeue always returns a cell, it creates it from the storyboard prototype if it is a new one - jrturton 2012-04-05 06:10


5

If your scrolling is poor in the device, you probably haven't configured your subviews correctly in the prototype. You aren't doing anything expensive in your method above.

Use the Core Animation instrument (device only) - check your frames per second when scrolling. You want as close as 60fps as possible.

Turn on "color blended layers" - anything drawn transparent will be highlighted in red. You want to remove all transparency, if possible, from your cells, and make them all green. This may simply be a matter of setting background colours and the opaque flag correctly in your prototype subviews.

If your images are not the same size as your image view, then you will be resizing every time a cell appears, this is an expensive operation as well.

2012-04-05 06:17
by jrturton
it has poor performance everywhere, in simulator and device - NCFUSN 2012-04-05 08:22
To put a finer point on it, there is no obvious reason for this to be slow. There is something else going on not related to this code - sosborn 2012-04-05 11:13
@jrturton Ok. Can it be the reason of poor performance if every image for cell stored in sandbox is 150x100 and then it getting resized by UIImageView to 38x31 automatically? I frankly to say, don't think that the images are so large, or is it - NCFUSN 2012-04-05 16:23
Dammit, I am getting 40fps - NCFUSN 2012-04-05 17:02
Resizing is expensive. You can comment out that part and see the effect. But you really should be using Instruments instead of guessing - jrturton 2012-04-05 17:03
Ah ! Crossed comments. You ARE using instruments - jrturton 2012-04-05 17:04
@jrturton Also, there's an issue with cell.imageView.image=[UIImage imageNamed:country.countryFlag]; line. I've got rid of imageNamed method and now using withContentOfFile: method. Of cause you know the difference, it HAS IMPROVED my performance. Also, I have resized the images and finally got ≈60 fps. Well, now there's another issue: why goddamit my images are so unsharp on Retina screen, but that's another question. Will google for it. Thank you for your answer and teaching me how to check scroll performance in Instruments. That was new for me - NCFUSN 2012-04-06 00:31
Ads