1

I have a complex view, let's say ComplexView, that consists of 10 labels, 2 buttons, 2 large images and I need to create it many times (scrolling, fast scrolling!) - texts and images are different in any two different ComplexView views.

Currently I am creating each ComplexView instance programmatically.

1) I wonder if there are some techniques to speed up the process of creating uiview each time?

2) The only option I see I could experiment: is to create a xib-file for this particular view and extract a generic part of my view there - will I get a benefit from that?

UPDATE: Similar question with detailed explanation of what Seamus Campbell said here in accepted answer: How to reuse/recycle custom element like uitableviewcell does?

Community
  • 1
  • 1
Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129

1 Answers1

2

The best way to achieve high performance displaying complex views is to take the UITableView approach and re-use offscreen views rather than creating new ones. The simplest way to do that is to just use a table view and custom cells, but it's also possible to roll-your-own if the table view's assumptions don't make sense.

Seamus Campbell
  • 17,816
  • 3
  • 52
  • 60
  • Thanks for the answer. _re-use offscreen views..._ and _"it's also possible to roll-your-own..."_ - could you please show an example of how this could be done? – Stanislav Pankevich Apr 05 '13 at 03:50
  • 1
    Like I said, UITableView provides the simplest model for doing this (and you should probably look at how it reuses views even if you don't use it). But if you don't want to use that, you can update your UIScrollView in -scrollViewDidScroll, removing items that have gone off-screen and putting them in a reuse cache, and for items that have come onscreen, pulling from the reuse cache and updating them to show the new data. – Seamus Campbell Apr 05 '13 at 04:01
  • Ah, these strings helped me to understand: putting/pulling in/from reuse cache ;) – Stanislav Pankevich Apr 05 '13 at 04:08