Andres Canella
Andres Canella

Reputation: 3716

Efficiently resize UITableViewCell on scroll

General Idea

Im looking to resize UITableViewCells dynamically as the user scrolls the list, to say, make the items grow in size as they reach the bottom of the list.

Considerations

This is a process that needs to be refreshed multiple times per second as a call is made to:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

So it is impractical to take the UITableView::ReloadData approach so that a call is made to:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

Since this will need to reload a bunch of extra data and slow down the system immensely.

Needs

Common knowledge

Possible approaches

Discarded approaches

So far

I've already coded a module that calculates the math for item size.

Conclusion

I'm looking for the quickest way to solved this but I will recode my own UITableView if needed as a last resort.

Thanks for your time.

Upvotes: 3

Views: 1603

Answers (3)

Andres Canella
Andres Canella

Reputation: 3716

After heavy testing with UITableView I have not found a way to do this efficiently. It seems that UITableView might be optimized in a way that does not permit dynamic cell resizing. For this reason making a custom listing system seems to be the only option. I have begun work on such project building on top of UIScrollView.

A large part of the basic functionality is complete but the project is currently on hold as I have a more important system to develop as of present. If you are interested in taking part in this project let me know.

Upvotes: 2

Brian Chapados
Brian Chapados

Reputation: 4916

You do not need to call -[UITableView reloadData] to update the geometry of cells. You can cause a UITableView to recalculate the geometry of cells by calling:

// force geometry update
[tableView beginUpdates];
[tableView endUpdates];

This was mentioned in the WWDC 2010 talk - Mastering Tableviews

Upvotes: 0

onetwopunch
onetwopunch

Reputation: 3329

Maybe check out tableView:willDisplayCell:forRowAtIndexPath in the uitableview delegate data sheet.

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html

I had a similar problem that I needed to load the table cells first, then do something different to each cell on after the table was loaded or reloaded, might be what you're looking for.

Cheers

Upvotes: 0

Related Questions