cell 的数据( 包含label,button等控件)总是为nil

Ansersion 2018-05-18 10:44:26
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

// Table view cells are reused and should be dequeued using a cell identifier.

guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? ScanResultTableViewCell else {
fatalError("The dequeued cell is not an instance of ScanResultTableViewCell.")
}

// Fetches the appropriate meal for the data source layout.
let cellData = scanResults[indexPath.row]

cell.scanResultNameLabel?.text = cellData.deviceName
cell.scanResultLogoImageView?.image = cellData.logo
return cell

}


debug查看结果,发现cell.scanResultNameLabel为nil,可是我在storyboard明明在cell中拖进了一个label,求教大神?
...全文
314 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ansersion 2018-05-18
  • 打赏
  • 举报
回复
全程使用storyboard开发,如果在代码中加入类似 scanResultTableView.register(ScanResultTableViewCell.self, forCellReuseIdentifier: cellIdentifier) 就会导致这样的问题。 唉,学艺不精啊

1,420

社区成员

发帖
与我相关
我的任务
社区描述
Swift,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C共同运行于MAC OS和iOS平台,用于搭建基于苹果平台的应用程序。
swift 技术论坛(原bbs)
社区管理员
  • Swift
  • 网罗开发
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧