Search code examples
iosswiftcocoa-touchreusability

iOS/Swift Equivalent of Android LayoutInflation


In Android to reuse views, a common manner of doing so is using a LayoutInflater in an Activity to get a view as an object which you can then manipulate and finally add to the Activity's content pane.

What is the equivalent pattern in iOS?

Use Case:

I have a group of objects that are to be displayed vertically down the phone screen. I would like to iterate over them, "inflate" a view, and then use the object's properties to set text and other properties of the view. I will then add the view to the main window.


Solution

  • I think the comments gave excellent advice. A UITableView seems perfect for what you describe. Just search Google for a UITableView tutorial. Here is an example:

    http://www.makemegeek.com/uitableview-example-ios/

    One the very good sites ti follow in general for tutorial is Ray Wenderlich:

    http://www.raywenderlich.com

    he just released his Swift book series:

    http://www.raywenderlich.com/store/swift-by-tutorials

    I think he has three new books in total and I am sure they are a bargain for what they will teach you.