ios - 意外发现nil tableView.registerNib

标签 ios xcode swift uitableview swift2

首先,我确实折叠了表格 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/

相关文章:

ios - 如何为 SKScene 的子类创建初始化程序

xcode - -[NSKeyedUnarchiver initForReadingWithData :]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?

ios - 检查当前时间是否在午夜后考虑的时间范围内 - Swift

php - 带地理定位的 Swift 自动推送通知

ios - 推送配置文件 OTA

iphone - 如何将事件添加到Tapku日历?

swift - 如何在 iOS (Swift) 中对 AWS Appsync 进行身份验证

ios - UIKit Dynamics - 缓慢移动的物体不会反弹

objective-c - 为 UITabBar 设置事件图像

swift - 在 swift playground 中使用 NSTimer