-
Notifications
You must be signed in to change notification settings - Fork 12
Advanced Views
Pegasus supports all of the view types such as UILabel
and UIImageView
easily enough, and the existing documentation should provide all you need to know.
However, there are certain views such as UITableView
and UIPickerView
which are more difficult to handle, because they need to be supplied with a data source from which they can get their values. Since the data source is normally supplied as a delegate object at runtime, this would normally mean that Pegasus isn't able to supply a table or picker view with values in the XML file. However, there is a way round this, which will allow you to populate these views using data sourced from the XML file itself.
UITableView
s can be specified using the tableview
Pegasus element, and you can treat it just as you would any other view.
Equally, UITableViewCell
s can be specified using the tableviewcell
Pegasus element, and it can also be treated as any other view.
However, you might be wondering at this point what happens if a tableviewcell
is specified as a sub-element of a tableview
, like this:
<tableview frame="fullscreen">
<tableviewcell text="Alpha" image="alpha.png" />
<tableviewcell text="Beta" image="beta.png" />
<tableviewcell text="Gamma" image="gamma.png" />
<tableviewcell text="Delta" image="delta.png" />
</tableview>
According to your existing knowledge of Pegasus, you would assume that the tableviewcell
s here would be added as subviews to the parent tableview
. Actually, Pegasus realises that tableviewcell
s shouldn't be added as subviews, and instead does the proper thing and adds them as actual cells to the table view, whilst any other sub-elements are treated as regular subviews.
One important consideration here is that the underlying PGTableView
object is now acting as the dataSourceDelegate
for this table view. You shouldn't re-assign the dataSourceDelegate
property unless that's really what you want to do (you can use delegate
to handle cell selections, etc. without affecting the dataSourceDelegate
).
A corollary of this is that you need to be careful about your view hierarchy being released while the table view is displaying (even if you're using ARC) because the PGTableView
(acting as the dataSourceDelegate
) is not retained. Therefore, you should probably let the view be an ivar of the view controller so it hangs around as long as the table view is in use.
Finally, please be aware that at the time of writing, table view support is currently very basic and many feature's aren't supported (see commit log for details).
Not yet supported.