我想有樂趣一些簡單的動畫,做給-do列表,但很齊全TableView.delegate與Segue公司的其他VC
我有問題,原因請看其他VC。 在一個ViewController我有TableView和按鈕。當你按下按鈕你移動(segue - push)到另一個VC,但是..當你使用另一個VC時,一切都沒問題,但是當我向第二個VC添加任何文本字段或其他東西時,一切都崩潰了,錯誤是:「致命錯誤:意外發現零而展開的可選值」顯示在tableView.delegate =自
哦!忘了它!每個出口都是正確的,並且單元格具有正確的ID。
我在做什麼錯?
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
let items: [String] = ["test1", "test2","tes3"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
print(tableView)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = items[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
@IBAction func buttonPressed(_ sender: AnyObject) {
performSegue(withIdentifier: "secondVC", sender: sender)
}
}
你檢查了'tableView'是否爲零? – Frankie
好了,所以,這是它的外觀http://imgur.com/a/A8kP6 而這正是發生在你按下按鈕 http://imgur.com/a/DANMg – Magnifique
您能不能告訴回調按鈕的「touchUpInside」動作的功能?同樣的問題與'準備(for segue :)'函數 – Dean