Search code examples
iosuitableviewuiviewreusability

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];

Solution

  • 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.