首先,我确实折叠了表格 View ,一切都很好,但是当我拖动按钮使我导航到另一个 Controller 时,它给了我错误
注意tableviewcell内的按钮
fatal error: unexpectedly found nil while unwrapping an Optional value
这是我的代码
// 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")
最佳答案
似乎您的 tableView 被声明为 UITableView!当您上面发布的代码被执行时,它不会被初始化。注册 nib 时,请确保 tableView 不为零。添加整个代码会有很大帮助。
关于ios - 意外发现nil tableView.registerNib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35859971/