scrollToRowAtIndexPath在iOS 8上无法正确滚动到底部

Kex*_*Kex 3 uitableview ios swift

这里有一个奇怪的问题.我想将我的表视图滚动到第1部分第0行的底部.我正在使用此代码:

tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 1), atScrollPosition: .Bottom, animated: true)
Run Code Online (Sandbox Code Playgroud)

它似乎在iOS 9.0及更高版本的模拟器中完美运行.但是在我的设备(iOS 8.1)和8.3的模拟器上,它完全相反.它滚动到单元格的顶部而不是底部!似乎很奇怪.我在这里做错了什么想法?非常感谢任何指针!谢谢

kab*_*rai 13

根据对类似问题的这个答案,它似乎是iOS 8中的一个错误.一种解决方法是将滚动延迟很短的数量(此代码也可以在链接的答案中找到,但它在Objective-中C).请注意,我没有测试此代码,因为我没有安装iOS 8 Simulator.

let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
    self.tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 1), atScrollPosition: .Bottom, animated: true)
} 
Run Code Online (Sandbox Code Playgroud)

编辑:这是Swift 3中的答案:

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
    self.tableView.scrollToRow(at: IndexPath(row: 0, section: 1), at: .bottom, animated: true)
}
Run Code Online (Sandbox Code Playgroud)