2016-09-29 14 views
1

我已經構建了一個非常簡單的演示應用程序來說明在安裝tableView時使用UIViewController時發現的兩個錯誤。如果我使用標準的UITableviewController,這些問題不存在。多個UITableViewBugs與refreshControl

Video to demonstrate the bug

project link to github

  1. 基本上,當我拉來慢慢的刷新,我得到這個跳躍(約30點)向下。我還需要在啓動清理程序之前拖動一段時間(大約一半的屏幕)。如果我儘快拉動,這個問題就不存在了。

  2. 如果我在實現hideNavigationBarOnSwipe和refreshControl的同時,節標題是因爲所有的醜陋和不合適的地方(稍後在視頻中顯示)。

我想知道,這類型的錯誤,如果我想採取了一槍,看看蘋果改進它,其中以下三個選項,我應該給它一個去。 (該項目是建立在xcode7.3,迅速2,IOS9.0

  1. 迅速從2到3,迅速
  2. 更新Xcode的更新從7至8
  3. 建立更高版本的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)" 
    } 
} 

回答

2
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 
} 
+0

的最佳解決方案。並感謝指點「UIRefreshControl不是子視圖,它們是爲了表格的刷新控制。 它假設它是一個單元格,而不僅僅是一個子視圖,它強制重新計算它。「 – user125972