0
func scroller() {
    let delay = 0.1 * Double(NSEC_PER_SEC)

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
        if self.chatMessages.count > 0 {
            let lastRowIndexPath = IndexPath(forRow: self.chatMessages.count - 1, inSection: 0)
            self.tblChat.scrollToRowAtIndexPath(lastRowIndexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: true)
        }
    }
}

我收到一个错误,它说 Argument labels '(forRow:, forSection:) 不匹配任何可用的重载,有帮助吗?

4

1 回答 1

3

在 Swift 3 中,您需要:

let lastRowIndexPath = IndexPath(row: self.chatMessages.count - 1, section: 0)
self.tblChat.scrollToRow(at: lastRowIndexPath at: .bottom animated: true)

您似乎正在尝试使用较旧的 Swift 2 API。

查看 和 的IndexPath文档UITableView。并尝试在输入代码时使用 Xcode 的自动完成功能。当然,如果您复制并粘贴旧代码,那将无济于事。

于 2017-05-09T20:14:43.633 回答