gpt4 book ai didi

ios - 预期返回 'UITableViewCell' 的函数中缺少返回值,但实际上返回了两次

转载 作者:搜寻专家 更新时间:2023-10-31 21:59:38 24 4
gpt4 key购买 nike

我正在尝试设置一个 TableView ,该 View 将根据顶部的分段 Controller 更改单元格。但是,在重新加载 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


}

}

View of the Table With Two different Custom UITableViewCells

最佳答案

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

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' 的函数中缺少返回值,但实际上返回了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39831026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com