ios - nib must contain exactly one top level object which must be a UITableViewHeaderFooterView instance -
i running weird issue when creating customheader tableview. error receiving following:
nib must contain 1 top level object must uitableviewheaderfooterview instance
i ran through code , xib file examples couldnt find wrong ideas missing?
the header xib created regular view , sub view label, class created following:
customtableheader class:
class customtableheader: uitableviewheaderfooterview { static var customtableheaderidentifier = "customtableheader" @iboutlet weak var titlelabel: uilabel! override awakefromnib(){ super.awakefromnib() self.titlelabel.text = "header" } override func prepareforreuse() { super.prepareforreuse() } }
viewcontroller class:
class viewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource { @iboutlet weak var tableview: uitableview! override func viewdidload() { super.viewdidload() self.tableview.register(uinib.init(nibname: customtableheader.customtableheaderidentifier, bundle: nil), forheaderfooterviewreuseidentifier: customtableheader.customtableheaderidentifier) } //other methods func tableview(_ tableview: uitableview, viewforheaderinsection section: int) -> uiview? { if let header = tableview.dequeuereusableheaderfooterview(withidentifier: customtableheader.customtableheaderidentifier) as? customtableheader { header.titlelabel.text = "section 1" return header } }
i figured out issue! in case ever runs this, make sure first view object in xib file. example on mine trying add gesture header view , considered object well. if want add gesture can programmatically:
addgesturerecognizer(uitapgesturerecognizer(target: self, action: #selector(/* function */)))
Comments
Post a Comment