我有一个tableViewController,它显示从解析中提取的一组用户。我通过UIRefreshControl
添加了“pull to refresh”,但每次点击refresher.endRefresher()
它都会使得我无法点击列表中的顶部单元格而第二个单元格只能在最底层点击细胞,靠近第三个细胞的顶部。我无法弄清楚为什么复习者会这样做。
这是一个short video showing what is happening:
以下是我的刷新功能和我的viewDidLoad
功能。
var refresher: UIRefreshControl!
func refresh() {
let query = PFUser.query()
query?.orderByAscending("username")
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let users = objects {
self.usernames.removeAll(keepCapacity: true)
self.userids.removeAll(keepCapacity: true)
self.isFollowing.removeAll(keepCapacity: true)
for object in users {
if let user = object as? PFUser {
if user.objectId! != PFUser.currentUser()?.objectId {
self.usernames.append(user.username!)
self.userids.append(user.objectId!)
let query = PFQuery(className: "followers")
query.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)
query.whereKey("following", equalTo: user.objectId!)
query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let objects = objects {
if objects.count > 0 {
self.isFollowing[user.objectId!] = true
} else {
self.isFollowing[user.objectId!] = false
}
}
if self.isFollowing.count == self.usernames.count {
self.tableView.reloadData()
print("refreshed")
self.refresher.endRefreshing()
}
})
}
}
}
}
})
}
override func viewDidLoad() {
super.viewDidLoad()
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to refresh")
refresher.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresher)
refresh()
}
我弄清楚发生了什么以及如何解决它。一旦我第一次拉动,似乎“拉动刷新”功能阻止了我的前两个单元格,因此解决方案是通过viewDidLoad
<tableView.sendSubviewToBack(refresher)
将复习发送到后面/ p>
override func viewDidLoad() {
super.viewDidLoad()
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to refresh")
refresher.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresher)
tableView.sendSubviewToBack(refresher)
refresh()
}