Using viewForHeaderInSection to get customized header in story board

I need to create a section header for a tableview, and I don't want to create it in single Xib, I added one in storyboard, but the header need some customization, so I create a file looks like this:
Code Block
class CustomizedTipsView: UITableViewHeaderFooterView {
    @IBOutlet weak var tipTitle: UILabel!
    @IBOutlet weak var tipContent: UILabel!
}

And I want to use the header in viewForHeaderInSection func like this:
Code Block
if let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "CustomizedTipsView") as? CustomizedTipsView {
            header.tipTitle.text = "1"
            header.tipContent.text = "2"
}

if I register the cell, it crash, if not, the cell always returns nil.

Code Block
//crash
mainTableView.register(UINib(nibName: "CustomizedTipsView", bundle: nil), forHeaderFooterViewReuseIdentifier: "CustomizedTipsView")
//crash too
mainTableView.register(CustomizedTipsView.self, forHeaderFooterViewReuseIdentifier: "CustomizedTipsView")


Do I have to use the UITableViewCell instead of simple CustomizedTipsView for view from storyboard?
Thank you for your help!



I don't want to create it in single Xib, I added one in storyboard

Can you tell me how you have set up your storyboard? As far as I know, storyboard does not support having prototypes of arbitrary header/footer view (which are available using dequeueReusableHeaderFooterView).

You may need to use .xib or create your CustomizedTipsView independent of storyboard.
I just drag and drop a view into the tableview in my storyboard, then I create a NewHeader class and make the view in the storyboard inherit NewHeader. I don't want to use xib instead, too much files, seems like the only way I can customize my header is to using UITableViewCell instead.
Using viewForHeaderInSection to get customized header in story board
 
 
Q