Note that there are some explanatory texts on larger screens.

plurals
  1. POtableView: cellForRowAtIndexPath: get called not only for visible cells?
    primarykey
    data
    text
    <p>I have a tableView with sections, which could be opened and closed. So, when I tap on a section to open it, it is getting filled up with cells and <code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)</code> get called exactly as much times as I provided in <code>-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section</code>. </p> <p>Is that correct? Shouldn't it be just number of visible cells? </p> <p>Because in my case I have bad situation: I have a lot of custom cells (50~100 cells) and calling <code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)</code> for each cell slows down the opening of a section, cause each time reading from nib is performed and cell content is being populated with image. I've check visibility of cell inside <code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)</code> like this:</p> <pre><code>if ([[self.tableView indexPathsForVisibleRows] containsObject:indexPath]) NSLog(@"visible %@", indexPath); </code></pre> <p>and it shows that from out of 45 cells, only 6 or 7 are visible. Others are out of visible area. But creating cells still performed. Here is the code:</p> <pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"IVCell"; IVCamera *camera = [server.cameras objectAtIndex:indexPath.row]; IVServerListViewCell *cell = (IVServerListViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"IVServerListCell" owner:self options:nil]; cell = (IVServerListViewCell*)_tableViewCell; self.tableViewCell = nil; } [cell textLabel].text = camera.cameraName; cell.preview = camera.preview; cell.userData = camera; cell.isEnabled = (server.isInactive)?NO:camera.isOnline; return cell; } </code></pre> <p>Is it still correct? Or am I missing something?</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. 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