ios - I've got an error in swift 3 -
i new swift 3 , i've got error couldnt find answer for... want make table view in custom design , part taht wanted register xib file.
// viewcontroller.swift // flash chat import uikit import firebase class chatviewcontroller: uiviewcontroller , uitableviewdelegate , uitableviewdatasource { @iboutlet var heightconstraint: nslayoutconstraint! @iboutlet var sendbutton: uibutton! @iboutlet var messagetextfield: uitextfield! @iboutlet var messagetableview: uitableview! override func viewdidload() { super.viewdidload() messagetableview.delegate = self messagetableview.datasource = self messagetableview.register(uinib(nibname : "messagecell" , bundle : nil), forcellreuseidentifier: "custommessagecell") } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "custommessagecell", for: indexpath) as! custommessagecell let messagearray = ["first message", "second message", "third message"] cell.messagebody.text = messagearray[indexpath.row] return cell } func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return 3 } @ibaction func sendpressed(_ sender: anyobject) { } @ibaction func logoutpressed(_ sender: anyobject) { { try firauth.auth()?.signout() } catch { print(error) } guard (navigationcontroller?.poptorootviewcontroller(animated: true)) != nil else { print("ther no view controller") return } } }
is typo mistake , initializer called in init(nibname:bundle:) not init(nibname:bundle:)
is
messagetableview.register(uinib(nibname : "messagecell" , bundle : nil), forcellreuseidentifier: "custommessagecell")
or use
messagetableview.register(uinib.init(nibname: "messagecell", bundle: nil), forcellreuseidentifier: "custommessagecell")
not
messagetableview.register(uinib(nibname : "messagecell" , bundle : nil), forcellreuseidentifier: "custommessagecell")
Comments
Post a Comment