Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse UIView like UITableViewCell

I have an app that has many instances of the same UIView. Is their a way to reuse a UIView like you can with UITableViewCell? Similar to:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
like image 829
lehn0058 Avatar asked Oct 06 '22 13:10

lehn0058


1 Answers

I suggest you watch session 104 of WWDC'2010 called "Designing Apps with ScrollViews" that explains the reuse mechanism (IIRC).

You can also look at the source of OHGridView in which I implemented this technique: look at the 2nd layoutSubviews method in OHGridView.m where I add unused UIViews in an NSMutableSet I called recyclePool, and then dequeue some UIViews from this recyclePool when I need one.

like image 75
AliSoftware Avatar answered Oct 10 '22 03:10

AliSoftware