Swift - 断言失败 in -[UITableView _configureCellForDisplay:forIn



tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell运行几次后我收到错误。
事情是这样的:我创建了一个包含用于单元格的数据的teacherArray,它肯定包含我需要的内容。
我使用情节提要来自定义单元格和表格视图。我已经检查了单元格的标识符是否已设置,并且我还在身份检查器中自定义了表视图和单元格的类。

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 {    
}

相关内容

  • 没有找到相关文章

最新更新