0
无我有这样的代码在我的控制器:意外地发现在迅速
var itemList:[String] = []
@IBOutlet var tasksTable:UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return itemList.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
var cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
cell.textLabel.text = itemList[indexPath.row]
return cell
}
override func viewWillAppear(animated: Bool) {
tasksTable.reloadData() <-----------------------
}
为什么会出现这个错误?
错误:意外地发现为零,而因为此刻viewWillAppear
展开一个可选值
我已经连接了插座。但是,最初阵列将是零。有没有办法处理无数组? – 2014-10-31 19:08:06
这实际上是Swift的一个非常棒的功能。如果Objective-C发生这种情况,_nothing_将会发生;你的表格视图不起作用,但你不知道为什么。这样,斯威夫特拍拍你,因为没有连接插座。 – matt 2014-10-31 19:08:32
哦..对不起..我忘了挂钩..谢谢 – 2014-10-31 19:09:57