【发布时间】:2024-01-04 17:46:03
【问题描述】:
我可能没有提供足够的信息来正确提出这个问题,但我试图找出为什么我的代码在加载到 indexPath.row 时会崩溃。
大部分代码被截断,这是我的 TableViewController.swift:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return minions.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return minionCellAtIndexPath(indexPath)
}
func minionCellAtIndexPath(indexPath:NSIndexPath) -> MinionCell {
let minion = minions[indexPath.row]
//Set the cell to be the custom, reusable, MinionCell
let cell = tableView.dequeueReusableCellWithIdentifier(minionCellIdentifier, forIndexPath: indexPath) as! MinionCell
if let name = minion.name {
cell.nameLabel?.text = minion.name
} else {
cell.nameLabel?.text = "No data available."
}
return cell
}
据我所知,let minion = minions[indexPath.row] 抛出错误,错误发生在 __Thread 1__ 上,语法显示:
函数签名特化 Arg[0] = 拥有保证
控制台输出似乎没有显示错误可能是什么,尽管我怀疑这是否与我从 Swift 1.2 过渡到 Swift 2 有关。
【问题讨论】:
-
您是否尝试过检查 minions 数组是否在该行之前填充?可能是表数据当时还没有准备好。我认为如果您在某处发布完整的测试用例以便人们可以自己运行它,您可能会获得更多帮助。只需使用说明问题的 tableview 创建一个测试项目。然后放到github或者类似的地方。
标签: swift uitableview swift2 nsindexpath