简体   繁体   中英

unexpectedly found nil tableView.registerNib

First of all, I did collapse tableview and everything is fine but when i drag button that make me navigate to another controller it give me error

Note that the button inside tableviewcell

fatal error: unexpectedly found nil while unwrapping an Optional value

this is my code

    // Do any additional setup after loading the view, typically from a nib.
    tableData = [
        ["title": "Gender", "height": "118", "cellID": "cell1"],
        ["title": "Componnet", "height": "205", "cellID": "cell2"],
        ["title": "Lille Attribute", "height": "905", "cellID": "cell3"],
        ["title": "Sensory Effect", "height": "215", "cellID": "cell4"],
        ["title": "Emotional Messages", "height": "338", "cellID": "cell5"],
        ["title": "Personalities", "height": "336", "cellID": "cell6"],
        ["title": "Country", "height": "97", "cellID": "cell7"],
        ["title": "Season", "height": "94", "cellID": "cell8"]
    ]
    expandSections = NSMutableArray() as [AnyObject]
    for var i = 0; i < tableData.count; ++i {
        expandSections .append(false);
    }
    tableView.registerNib(UINib(nibName: "TableViewCell1", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell1") // in this line
    tableView.registerNib(UINib(nibName: "TableViewCell2", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell2")
    tableView.registerNib(UINib(nibName: "TableViewCell3", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell3")
    tableView.registerNib(UINib(nibName: "TableViewCell4", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell4")
    tableView.registerNib(UINib(nibName: "TableViewCell5", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell5")
    tableView.registerNib(UINib(nibName: "TableViewCell6", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell6")
    tableView.registerNib(UINib(nibName: "TableViewCell7", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell7")
    tableView.registerNib(UINib(nibName: "TableViewCell8", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell8")

Seems like your tableView is being declared as UITableView! and it's not initialized when the code you posted above gets executed. Make sure the tableView is not nil when you're registering the nibs. Adding the entire code would help a lot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM