我在 tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
运行几次后收到错误。
事情是这样的:我创建了一个包含用于单元格的数据的 teacherArray
,它肯定包含我需要的数据。
我使用 Storyboard来自定义单元格和表格 View 。我检查了单元格的标识符是否已设置,我还在身份检查器中为表格 View 和单元格自定义了类。
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return teacherArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("SearchCell", forIndexPath:indexPath) as SearchCell
cell.nameLabel.text = teacherArray[indexPath.row].name
cell.schoolLabel.text = teacherArray[indexPath.row].school
cell.experienceLabel.text = teacherArray[indexPath.row].experience
cell.courseLabel.text = teacherArray[indexPath.row].course
println(indexPath.row)
println(cell)
return cell
}
我已经跟踪了这个方法,它在这个控制台输出之后:
6
PAL.SearchCell: 0x7bf32310; baseClass = UITableViewCell; frame = (0 450; 320 75); autoresize = W; layer = <CALayer: 0x7bf322e0>
...我收到此错误消息:
2015-04-26 22:27:54.880 PAL[65213:6357947]*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.93/UITableView.m:7344
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
我不知道我做错了什么。有什么想法吗?
最佳答案
试试这个:
add UITableViewDataSource, UITableViewDelegate:
class HDMainHotBoleCtr: UIViewController, UITableViewDataSource, UITableViewDelegate {
}
关于ios - Swift - 断言失败 -[UITableView _configureCellForDisplay :forIndexPath:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29879232/