monkeydog
monkeydog

Reputation: 27

Storyboards and subclasses

I've been working in iOS for a bit but have mostly worked on a project that never used storyboards. Everything is in code, and I'm not too experienced with Storyboards.

I'm trying to understand how to implement a BaseTableViewController and have all my table view controllers subclass that. I want to keep one tableView in this superclass.

So say I create FirstTableViewController and SecondTableViewController subclasses off of BaseTableViewController. I add tableViews to each so that I can set my Protoype Cells for each distinctive subclass. Then I add and connect these in my storyboard.

Where I'm confused is that now I have tableViews in the storyboard for each subclass VC, but then I want to keep the superclass tableView as the only tableView.

How to reconcile this?

Upvotes: 0

Views: 47

Answers (1)

user3435374
user3435374

Reputation: 1296

I would recommend that you place your table view prototype cell in a Xib file instead of placing them in the storyboard prototype. That way you do not have to create the tableviews in your BaseTableView subclasses. You register the table view cells in the viewdidload of the Tableview controller subclasses using code like this

     let cellNib = UINib(nibName: "xibfileforTableViewCell", bundle: NSBundle.mainBundle())
     tableView.registerNib(cellNib, forCellReuseIdentifier: cellReuseIdentifier)

You can still use outlets from the xib files just like storyboards

Upvotes: 1

Related Questions