HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 函数中缺少返回预期返回’UITableViewCell’,但实际返回两次大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试设置一个表视图,它将根据顶部的分段控制器更改单元格.但是,在重新加载tableview时尝试更改单元格时,我收到了返回函数错误,而实际上我有一个返回函数.我该怎么做才能解决这个问题?

func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {




    if friendSELEctor.SELEctedSegmenTindex == 0 {
        print("0")

        cell = self.friendsTable.dequeueReusableCell(withIdentifier: "cell",for: indexPath) as! FriendsTableViewCell


        cell.nameLabel.text = friends[indexPath.row]
        cell.BACLabel.text = String(friendsBAC[indexPath.row])
        cell.statusImageView.image = friendsImage[indexPath.row]

        return cell

    }

    if friendSELEctor.SELEctedSegmenTindex == 1 {
        print("1")

        celladd = self.friendsTable.dequeueReusableCell(withIdentifier: "celladd",for: indexPath) as! FriendsAddTableViewCell

        celladd.nameLabel.text = requested[indexPath.row]
        celladd.statusImageView.image = UIImage(named: "greenlight")

        return celladd


    }

}

ios – 函数中缺少返回预期返回’UITableViewCell’,但实际返回两次

解决方法

你应该返回一个单元格.在上面的代码中,如果两个条件都失败,则不会返回任何内容.所以提出警告.只需删除第二个“if”条件并使用else情况如下:

func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if friendSELEctor.SELEctedSegmenTindex == 0 {
        print("0")

        cell = self.friendsTable.dequeueReusableCell(withIdentifier: "cell",for: indexPath) as! FriendsTableViewCell


        cell.nameLabel.text = friends[indexPath.row]
        cell.BACLabel.text = String(friendsBAC[indexPath.row])
        cell.statusImageView.image = friendsImage[indexPath.row]

        return cell

    }

    else {
        print("1")

        celladd = self.friendsTable.dequeueReusableCell(withIdentifier: "celladd",for: indexPath) as! FriendsAddTableViewCell

        celladd.nameLabel.text = requested[indexPath.row]
        celladd.statusImageView.image = UIImage(named: "greenlight")

        return celladd


    }

}

大佬总结

以上是大佬教程为你收集整理的ios – 函数中缺少返回预期返回’UITableViewCell’,但实际返回两次全部内容,希望文章能够帮你解决ios – 函数中缺少返回预期返回’UITableViewCell’,但实际返回两次所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。