UITableView loads every cell

Should a UITableview only load cells that are first visible on the right? My table looks at each cell initially, which slows it down. I use about 1000 lines. Just want it to load a cell when it should (for example, scrolling a user). Anyone have any ideas why this is being done?

+4
source share
4 answers

I know that cellForRowAtIndexPath is first called for each cell. The height of the cells is 89.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UILabel *textName = nil; UIImageView* image = nil; unsigned int DATA_TAG = 1001; unsigned int IMG_TAG = 1002; // Retrieve a cell is Available cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Check if no new cell was available if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; // Set the Accessory Data textName = [[[UILabel alloc]initWithFrame:CGRectMake(cell.frame.origin.x, 80, cell.frame.size.width, 20)]autorelease]; textName.tag = DATA_TAG; textName.textAlignment = UITextAlignmentCenter; textName.backgroundColor = [UIColor clearColor]; textName.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0]; textName.textColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]; textName.lineBreakMode = UILineBreakModeWordWrap; [cell.contentView addSubview:textName]; //Set the Image Data image = [[[UIImageView alloc]initWithFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, 80)]autorelease]; image.tag = IMG_TAG; image.contentMode= UIViewContentModeScaleAspectFit; [cell.contentView addSubview:image]; } Accessory* acc= [[AccessoryManager sharedManager].currentList objectAtIndex:indexPath.row]; if(acc == nil) return cell; textName= (UILabel*)[cell.contentView viewWithTag:DATA_TAG]; textName.text= acc.accessoryName; image= (UIImageView*)[cell.contentView viewWithTag:IMG_TAG]; [image setImage:acc.accessoryImage]; return cell; } 
+1
source

Can you send some kind of code? The -tableView: cellForRowAtIndexPath method is called only when a new "slot" for a potential cell is opened, so you need to do something serious wrong to "load every cell" initially!

Perhaps you mean that you download all the data first and want to do it in batches?

0
source

That's right - it should download only those that it needs. What is your UITableView rowHeight ? If this was extremely small, the table may need to load all cells

If this is not a problem, can you insert the code for tableView:cellForRowAtIndexPath: :?

0
source

Are you calling cellForRowAtIndexPath yourself, for example, from heightForRowAtIndexPath? If so, you do not need to create a cell to determine its height.

0
source

All Articles