大佬教程收集整理的这篇文章主要介绍了如何使tableview单元格可见?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个 UItableVIEw 并使用以下代码添加了单元格:
import UIKit
class VIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDatasource {
@IBOutlet weak var tableVIEw: UItableVIEw!
let storIEs = [Story(title("Story1",UIImage(named: "story1image"),"Earth day has been...."),Story(title("Story2",UIImage(named: "story2image"),"Martian rover is....")
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
// Do any additional setup after loading the vIEw.
tableVIEw.delegate = self
tableVIEw.datasource = self
tableVIEw.register(StoryCell.self,forCellReusEIDentifIEr: "storyCell")
self.tableVIEw.reloadData()
print((self.tableVIEw.visibleCells[0] as! StoryCell).body) // Returns the correct story body.
}
func tableVIEw(_ tableVIEw: UItableVIEw,numberOfRowsInSection section: int) -> Int {
//Returns the number of rows as the number of storIEs
return storIEs?.count ?? 2
}
func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {
//Initializes Cell
let cell = tableVIEw.dequeueReusableCell(withIDentifIEr: "storyCell",for: indexPath) as! StoryCell
//Customizes Cell
cell.title = storIEs?[indexPath.row].title.title ?? "ERROR"
cell.icon = storIEs?[indexPath.row].title.icon
cell.body = storIEs?[indexPath.row].body ?? "ERROR"
return cell
}
}
当我运行代码时,它会打印正确的故事正文,这意味着 tablevIEw 具有单元格,但单元格不存在且可见。在屏幕上,tablevIEw 是空白的。我想知道如何使单元格可见。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的如何使tableview单元格可见?全部内容,希望文章能够帮你解决如何使tableview单元格可见?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。