2016-03-08 86 views
0

首先,我沒有崩潰的tableview,一切都很好,但是當我拖動按鈕,使我導航到另一個控制器,它給我的錯誤意外地發現零tableView.registerNib

注意是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") 
+1

你如何創建tableview,你可以顯示一次 –

+0

你註冊了你的筆尖嗎? – iamalizade

+0

我以編程的方式創建它 –

回答

0

好像你的tableView被宣佈爲UITableView的!當你上面發佈的代碼被執行時,它不會被初始化。當你註冊nib時,確保tableView不是零。添加整個代碼會有很大幫助。