iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 使用UITableView和数组的无限滚动大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 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
    }
}

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

非常感谢.

@H_262_14@解决方法
虑使用 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和数组的无限滚动所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。