For example, if I required a UITableView
to appear beneath additional content in a view, would it be best practice to either:
UITableView
as a subview, orUITableViewController
?As far as I know, both would provide the same user experience, however I am interested to know which method would be considered best practice?
You have several options:
UITableView
and make the containing view controller the table view's data source and delegate.UITableView
and make some other class the table view's data source and delegate.The choice depends on the appropriate division of responsibility and encapsulation.
Options 2 & 3 allow for reuse if you ever need to embed the table view in more than one view controller.
There is no simple answer to your question. It all depends on your needs, your data, and your app's structure.
The general rule for iOS, especially for the iPhone/iPod touch form factor, is that you should have only one view controller on the screen at any given time. The only case I can think of when you would want to violate that guideline is when you have a subview that has a lot of logic built in to it, and the subview needs to be included in multiple other views. For example, a popover should have its own view controller because it might need to be shown in conjunction with multiple other view controllers.
In your case, I would strongly suggest just adding the UITableView as a subview unless (1) the table view has a lot of logic that isn’t related to that of the parent view controller, or (2) you will need to display the same table view in another part of your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With