Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, I somehow dealt with my problem. Here are my ideas and thoughts how I came to the solution. Maybe it could be helpful to somebody.</p> <p>I've instructed memory allocations and call stack using Instruments during opening section events. It showed me, that the majority of time is spent on loading cell from nib file. </p> <p>Firstly, that I've done was <strong>reducing the size of nib file</strong>, i.e. minimizing the number of views used in custom tableview cell (now its only 2 views and 2 labels, instead of 6 views, 2 images and 2 labels before). It gave me some improve in cells loading. Apple documentation suggests to use as few as possible views and do not use transparency. So be attentive to these suggestions.</p> <p>Secondly, as I discovered earlier, that not all cell are visible which are created by <code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)</code>, I decided to reduce somehow the number of loadings new cells from nib file. To achieve this, I've came to simple idea: return blank default cells for invisible rows, while load custom cells from nib for visible ones. Here is the piece of code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([self index:indexPath isInvisibleInTableView:tableView]) return [self getBlankCellForTableView:tableView]; // the rest of the method is the same ... } -(BOOL)index:(NSIndexPath*)indexPath isInvisibleInTableView:(UITableView*)tableView { NSMutableArray *visibleIndexPaths = [self getExtendedVisibleIndexPathsForTableView:tableView]; return ![visibleIndexPaths containsObject:indexPath]; } -(UITableViewCell*)getBlankCellForTableView:(UITableView*)tableView { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IVBlankCell"]; if (!cell) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"IVBlankCell"] autorelease]; return cell; } </code></pre> <p>As you can see, I'm not using just <code>-(NSArray*)indexPathsForVisibleRows</code> method of tableview for detecting visible cells. Instead, I've wrote my own method <code>-(NSMutableArray*)getExtendedVisibleIndexPathsForTableView:(UITableView*)tableView</code>. It was necessary because for some reason, when using <code>-(NSArray*)indexPathsForVisibleRows</code> the cells that are next to the last one visible cell or the cells that are previous to the first one visible cell were created as blank cells and looked like empty cells while scrolling. To overcome this, in <code>-(NSMutableArray*)getExtendedVisibleIndexPathsForTableView: (UITableView*)tableView</code> i'm adding border cells to the visible array cells:</p> <pre><code>-(NSMutableArray*)getExtendedVisibleIndexPathsForTableView:(UITableView*)tableView{ NSArray *visibleIPs = [tableView indexPathsForVisibleRows]; if (!visibleIPs || ![visibleIPs count]) return [NSMutableArray array]; NSIndexPath *firstVisibleIP = [visibleIPs objectAtIndex:0]; NSIndexPath *lastVisibleIP = [visibleIPs objectAtIndex:[visibleIPs count]-1]; NSIndexPath *prevIndex = ([firstVisibleIP row])?[NSIndexPath indexPathForRow:[firstVisibleIP row]-1 inSection:[firstVisibleIP section]]:nil; NSIndexPath *nextIndex = [NSIndexPath indexPathForRow:[lastVisibleIP row]+1 inSection:[lastVisibleIP section]]; NSMutableArray *exVisibleIndexPaths = [NSMutableArray arrayWithArray:[tableView indexPathsForVisibleRows]]; if (prevIndex) [exVisibleIndexPaths addObject:prevIndex]; [exVisibleIndexPaths addObject:nextIndex]; return exVisibleIndexPaths; } </code></pre> <p>Thereby, I've reduced the time of opening sections with large number of custom cells, which was proved by Instruments tracing and felt while experiencing the app.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload