RefreshControl bugs first Cell of TableView, after using Back on NavBar

这一生的挚爱 提交于 2021-02-10 12:58:22

问题


I have a TableView embedded in NavigationController (and that's embedded in a TabBar Controller). I have a username button in each cell that segues to the user's profile.

However after I hit 'back' on the profile page's nav bar, and gets directed back to tableview, it seems like I bugged something.

And if I pull down again, it refreshs but this time, top row's username becomes unclickable while other rows work as expected.

Please note that I call self.theRefreshControl = UIRefreshControl() in viewDidLoad in tableView but I am not sure if it is or isn't getting called, after using Back button.

Please note that I perform segue with prepareForSegue.


To wrap up

  • If I go to the notifications page and try clicking username, username button click and segue works

  • If I go to the notifications, and pull the refresh, username button in first row doesn't work

  • If I go to the notifications and don't do any refresh, the username buttons segues and back works (so it doesn't bug).

  • If I go to the notifications and pull to refresh, the refreshControl icon appears and disappears, but now, it doesn't let me click on the username button on the top row.

  • If I do refresh on notifications, it doesn't let me click on the username in the top row. If I click on the second username in the second cell, it segues to user's profile, but when I click back button, then it bugs like this:

Code in ViewDidLoad():

 override func viewDidLoad() {
  super.viewDidLoad()

  self.theRefreshControl = UIRefreshControl()
  self.theRefreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
  self.theRefreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
  self.tableView.addSubview(theRefreshControl)
}

func refresh(sender: AnyObject) {
   if isFirstLoad == false {
      currentPage = 1
       getStuff()
    }

   self.theRefreshControl.endRefreshing()
}

I also tried adding self.tableView.backgroundView = refreshControl above and below self.tableView.addSubview(theRefreshControl); and also tried replacing self.tableView.addSubview(theRefreshControl) with self.tableView.backgroundView = refreshControl but unfortunately no luck


回答1:


The way you should instantiate the refreshControl is like so:

override func viewDidLoad() {
    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: "refresh:", forControlEvents: .ValueChanged)
    tableView.backgroundView = refreshControl // <- THIS!!!
}

as stated in this answer.

My guess is that your refreshControl is in front of your cells, so if the above doesn't work try this: tableView.sendSubviewToBack(theRefreshControl) in viewDidLoad

EDIT: Since tableView.sendSubviewToBack(theRefreshControl) was the solution, consider filing a bug with Apple, since it should happen automatically when you set the refreshControl as the tableView.backgroundView



来源:https://stackoverflow.com/questions/35391236/refreshcontrol-bugs-first-cell-of-tableview-after-using-back-on-navbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!