TableView.delegate与Segue公司的其他VC
问题描述:
我想有乐趣一些简单的动画,做给-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)
}
}
答
你的第二个VC分配有错误的类。在IB中,选择第二个视图控制器并选择Utilities面板的第三个选项卡。我的猜测是你的课程设置为ViewController
,但当然第二个VC应该是它自己的课程。
+0
第二个VC的类设置为customClass,它是“AddTaskVC”.. – Magnifique
你检查了'tableView'是否为零? – Frankie
好了,所以,这是它的外观http://imgur.com/a/A8kP6 而这正是发生在你按下按钮 http://imgur.com/a/DANMg – Magnifique
您能不能告诉回调按钮的“touchUpInside”动作的功能?同样的问题与'准备(for segue :)'函数 – Dean