gpt4 book ai didi

ios - 多个带有刷新控件的UITableViewBugs

转载 作者:行者123 更新时间:2023-12-01 20:02:02 25 4
gpt4 key购买 nike

我已经构建了一个非常简单的演示应用程序,以说明在使用安装了tableView的UIViewController时发现的两个错误。如果我使用标准的UITableviewController,则不会出现这些问题。

Video to demonstrate the bug

project link to github

  • 基本上,当我慢慢拉动刷新时,我会向下跳跃(大约30点)。在激活更新程序之前,我还需要向下拖动一点(大约一半的屏幕)。如果我拉得很快,问题就不存在了。
  • 如果我同时实现hideNavigationBarOnSwipe和refreshControl,则该节标题很丑陋且不合适(在视频的后面显示)。

  • 我想知道,对于这种错误,我是否想试一下苹果是否改进了它,我应该尝试以下三个选项中的哪个。 (此项目基于xcode7.3,swift 2,IOS9.0构建
  • 从swift 2更新到swift3。
  • 将Xcode从7更新为8
  • 为更高的IOS版本构建应用程序

  • ----完整代码----
    import UIKit

    class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var myTableView: UITableView!

    var refreshControl: UIRefreshControl!

    override func viewDidLoad() {
    super.viewDidLoad()
    myTableView.delegate = self
    myTableView.dataSource = self

    navigationController!.hidesBarsOnSwipe = true

    refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: #selector(ViewController.refresh), forControlEvents: .ValueChanged)
    myTableView.addSubview(refreshControl)
    }

    func refresh() {

    }

    @IBAction func stopRefreshingBtnPressed(sender: AnyObject) {
    refreshControl.endRefreshing()
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 10
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 10
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)
    cell.textLabel?.text = "section \(indexPath.section) row \(indexPath.row)"
    return cell
    }

    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 20
    }

    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return "Section Header \(section)"
    }
    }

    最佳答案

     override func viewDidLoad() {
    super.viewDidLoad()
    myTableView.delegate = self
    myTableView.dataSource = self
    navigationController!.hidesBarsOnSwipe = true

    refreshControl = UIRefreshControl()

    //Create an instance of a UITableViewController. This will host your UITableView.
    let tableController = UITableViewController()

    //Add tableController as a childViewController and set its tableView property to your UITableView.
    self.addChildViewController(tableController)
    tableController.tableView = myTableView
    tableController.refreshControl = self.refreshControl
    }

    关于ios - 多个带有刷新控件的UITableViewBugs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39776247/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com