1 Reply
      Latest reply on May 21, 2019 9:11 AM by Claude31
      edgeoftheatlas Level 1 Level 1 (0 points)

        Why is it if I have a UITableView and I display cells that it fires the willDisplayCell for every cell that is in the table? One cell takes up about 40% of the display. So at most 4-5 cells should be prepared and fire the cellForRowAtIndexPath method along with the willDisplayCell method. It shouldn't fire all 15! It's killing the performance of my tableview.

         

         

        -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
            // vars
            SimpleTVCell *tempCell = (SimpleTVCell *)[tableView dequeueReusableCellWithIdentifier:simpleTVCellIdentifier];
            NSLog(@"temp cell %@", tempCell);
            
            // return
            return tempCell;
        }
        
        -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
            // vars
            SimpleTVCell *tempCell = (SimpleTVCell *)cell;
            
            NSLog(@"will display cell %d", indexPath.row);
        }
        
        • Re: Weird UITableViewBehavior
          Claude31 Level 8 Level 8 (5,845 points)

          I have tested with a table with 50 rows.

          There is room on screen to display about 12.

           

          The func is

              func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
                 
                  print(#function, indexPath.row)
              }

           

          When loading, I just get willDisplay called for 12 rows. Not the whole table.

          And then, when scrolling, additional rows are handled in will display.

           

          So, behaves as expected, not as your case.A few questions:

          - which version of XCode ?

          - Have you defined the estimatedRowHeight ?

          https://developer.apple.com/documentation/uikit/uitableview/1614925-estimatedrowheight

           

          This discussion on how those API work may interest you:

          h ttps://jobs.zalando.com/tech/blog/proper-use-of-cellforrowatindexpath-and-willdisplaycell/?gh_src=4n3gxh1