I'm new to iOS. I'm currently developing an iOS application and I have a small question to you. I have few ViewControllers which Views are the same - a tableView with some data. Only the logic is different - if you select a row, different things happen, also the rows look a little bit different, but those differences are made in the ViewControllers code. My question is, what is the proper way for creating xibs for those ViewControllers? Should I create new xib for each ViewController or just one for all of them? If one, what with the FilesOwner of xib? I set it in xCode, so should I change it or what? Is it good to have only one View? Thank you!
One xib, many ViewControllers - is it a proper way?
490 views Asked by Jonatan Dragon At
3
There are 3 answers
2
On
The previous answer is right, but I don't feel confortable instantiating ViewControllers or using xib in code. I let the segues do all the work.
I would have a base class, let's say GenericTableViewController and define common behavior there (like IBActions or interactions with the UI), the view is also inherited so all the subclasses (viewcontrollers) share it.
If all views are
UITableView
s you would only need one xib file (lets name it GenericTableView.xib), add yourUITableView
, connect it with the file owner which is simply aUITableViewController
. After that create separate subclasses ofUITableViewController
and implement your specific behavior in there.In your code you can the easily initiate any of your
UITableViewController
subclasses with