iOS12-crash错误-reason: 'UITableView failed to obtain a cell from its dataSource'

747 阅读1分钟

错误原因:

cellForRowAtIndexPath函数返回了nil

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)

        // Configure the cell...

        return cell
    }

解决方法:

检查:

1.storyboard上有没有给cell加identifier

2.identifier有没有写错

3.函数本身是不是还没实现

4.if else返回其中一个cell时的判断错乱了

5.想到再加

 

广告时间:小弟的iOS12零基础视频教程(每章皆可试听):

m.study.163.com/provider/48…