ios – 使用UITableView和数组的无限滚动

ios – 使用UITableView和数组的无限滚动,第1张

概述我是 Swift的新手,我想用数组进行无限滚动.这是我的ClassViewController类 class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var legumes: [String] = ["Eggs", "Milk", "Chocolat", "Web", 我是 Swift的新手,我想用数组进行无限滚动.这是我的ClassVIEwController类

class tableVIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDataSource {  var legumes: [String] = ["Eggs","Milk","Chocolat","Web","MIEl","Pop","Eco","Moutarde","Mayo","Thea","Pomelade","Gear","Etc","nop","Dews","Tout","Fun","Xen","Yoga" ]  overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    self.tableVIEw.delegate = self    self.tableVIEw.dataSource = self    func numberOfSections(in tableVIEw: UItableVIEw) -> Int {      return 1    }    func tableVIEw(_ tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {       return self.legumes.count    }    func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {      let cell = self.tableVIEw.dequeueReusableCell(withIDentifIEr: "Cell",for: indexPath) as! ImagetableVIEwCell      return cell    }}

我想显示我的数组的前十项,当我在tableVIEwController的底部时,它将加载接下来的十个项目,等等.我不知道怎么做,我在GitHub上看到很多代码但是我不知道如何实现它们.

非常感谢.

解决方法 考虑使用 PagingTableView

class MainVIEwController: UIVIEwController {  @IBOutlet weak var contenttable: PagingtableVIEw!  var legumes: [String] = ["Eggs","Yoga" ]  overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    contenttable.dataSource = self    contenttable.pagingDelegate = self  }}extension MainVIEwController: UItableVIEwDataSource {  func tableVIEw(_ tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {    return legumes.count  }  func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {    let cell = tableVIEw.dequeueReusableCell(withIDentifIEr: "Cell",for: indexPath) as! ImagetableVIEwCell    guard legumes.indices.contains(indexPath.row) else { return cell }    cell.content = legumes[indexPath.row]    return cell  }}extension MainVIEwController: PagingtableVIEwDelegate {  func paginate(_ tableVIEw: PagingtableVIEw,to page: Int) {    contenttable.isLoading = true    dispatchQueue.main.asyncAfter(deadline: .Now() + 1) {      self.legumes.append(contentsOf: legumes)      self.contenttable.isLoading = false    }  }}

修改paginate函数以按您的意愿工作

总结

以上是内存溢出为你收集整理的ios – 使用UITableView和数组的无限滚动全部内容,希望文章能够帮你解决ios – 使用UITableView和数组的无限滚动所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1002274.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存