ios - 预测tableView swift 4
问题描述
我有 2 个 tableView 和 2 个 tableView 首先显示预测文本的数据和秒,我使用 textField 作为 searchBar 所以当我为 sec tableView 设置单元格时,当我尝试在cellForRowAt
方法返回单元格时给我那个错误
无法将类型的返回表达式转换UITableViewCell.Type
为返回类型UITableViewCell
这就是我的代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == tableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "SearchCell", for: indexPath) as! searchCell
//cell.pics = receiveData[indexPath.item]
cell.titleCell.text = receiveData[indexPath.row].adeTitle
cell.cityCell.text = receiveData[indexPath.row].city
cell.dateCell.text = receiveData[indexPath.row].date
cell.distanceCell.text = receiveData[indexPath.row].distance
cell.priceCell.text = receiveData[indexPath.row].adePrice
if receiveData[indexPath.row].typ == "2" {
cell.kindCell.text = "used"
cell.kindCell.backgroundColor = UIColor.darkGray
cell.kindCell.textColor = UIColor.white
} else if receiveData[indexPath.row].typ == "1" {
cell.kindCell.text = "New"
} else {
cell.kindCell.text = "none"
cell.kindCell.backgroundColor = UIColor.darkGray
cell.kindCell.textColor = UIColor.white
}
} else {
var cell = searchTableView.dequeueReusableCell(withIdentifier: "Cell" )
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
}
cell?.textLabel?.text = inputs[indexPath.row]
}
return UITableViewCell
}
解决方案
看起来您的方法UITableViewCell
中没有返回 ' 实例,cellForRowAt
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == tableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "SearchCell", for: indexPath) as! searchCell
...
// do your stuffs with cell
...
return cell
}
return UITableViewCell()
}
推荐阅读
- javascript - React:返回另一个组件中的函数
- optimization - AnyLogic 自定义实验卡住没有任何错误
- javascript - HTML DOM appendChild 脚本异步
- http - 缓存资源一段时间,然后使用 HTTP 缓存对其进行验证
- c# - 我正在尝试使用 c# 和 IDK 统一创建一个健康栏,其中我弄乱了代码,这是我的处理脚本,它一直说:NullException
- python-3.x - 如何使用 pyppeteer 异步获取 url(一个浏览器多个选项卡)
- javascript - 从 innerHtml 中删除特定标签并将其呈现在反应页面上
- r - 在连续的 ggplot-legend 中添加 NA 值的条目
- python-3.x - 计算组内两个日期时间之间的时间差
- reactjs - 如果广告单元尺寸相同,Google Ads 不会呈现