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 ?

Community
  • 1
  • 1
NCFUSN
  • 1,624
  • 4
  • 28
  • 44
  • Have you set the cell ID of your CountryCell nib to "Cell"? Have you registered the nib with registerNib:forCellReuseIdentifier:? – JiaYow Apr 04 '12 at 23:19
  • 1
    are the cells using custom height or some other delegate method that has known performance issues? – Jesse Naugher Apr 05 '12 at 01:45
  • How big is the country.countryFlag image? Where is that image coming from? – sosborn Apr 05 '12 at 02:32
  • @ Jesse Naugher No,cells are standard. @sosborn flag image is 100x100 and coming from images folder in sandbox. – NCFUSN Apr 05 '12 at 03:47
  • 1
    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 Apr 05 '12 at 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 Apr 05 '12 at 04:58
  • @Nathan Day Yes. And subclass too. – NCFUSN Apr 05 '12 at 05:01
  • 1
    @NathanDay - with storyboards, dequeue always returns a cell, it creates it from the storyboard prototype if it is a new one. – jrturton Apr 05 '12 at 06:10

1 Answers1

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.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • 1
    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 Apr 05 '12 at 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 Apr 05 '12 at 16:23
  • Resizing is expensive. You can comment out that part and see the effect. But you really should be using Instruments instead of guessing. – jrturton Apr 05 '12 at 17:03
  • Ah ! Crossed comments. You ARE using instruments! – jrturton Apr 05 '12 at 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 Apr 06 '12 at 00:31