Well, I somehow dealt with my problem. Here are my ideas and thoughts, how I came to a decision. Maybe it can be useful to someone.
I instructed the memory allocation and call stack using tools during the events of the opening section. He showed me that most of the time is spent loading a cell from a nib file.
Firstly, I did this by reducing the size of the nib file , i.e. minimizing the number of views used in the user tableview cell (now its only 2 views and 2 labels instead of 6 views, 2 images and 2 labels before). This gave me some improvement in cell loading. Apple documentation suggests using as few views as possible and not using transparency. Therefore, be attentive to these offers.
Secondly, as I discovered earlier, that not all cells are visible that are created -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) , I decided to somehow reduce the number of downloads of new cells from the nib file. To achieve this, I came up with a simple idea: return empty cells by default for invisible rows, and load custom cells from nib for visible ones. Here is the code snippet:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([self index:indexPath isInvisibleInTableView:tableView]) return [self getBlankCellForTableView:tableView];
As you can see, I do not use only the method -(NSArray*)indexPathsForVisibleRows tableview to detect visible cells. Instead, I wrote my own method -(NSMutableArray*)getExtendedVisibleIndexPathsForTableView:(UITableView*)tableView . This was necessary because for some reason when using -(NSArray*)indexPathsForVisibleRows cells that are next to the last visible cell or the cells preceding the first visible cell were created as empty cells and looked like empty cells when scrolling. To overcome this, in -(NSMutableArray*)getExtendedVisibleIndexPathsForTableView: (UITableView*)tableView I add boundary cells to the cells of the visible array:
-(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; }
Thus, I reduced the opening time of sections with a large number of user cells, which was proved by the tracing of tools and the feeling when working with the application.
peetonn
source share