ios - 使用 tableview 时 xcode 中的可用重载

标签 ios swift uitableview indexpath

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)
        }
    }
}

我收到一个错误,它说参数标签'(forRow:, forSection:) 不匹配任何可用的重载,有什么帮助吗?

最佳答案

在 Swift 3 中你需要:

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

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

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

关于ios - 使用 tableview 时 xcode 中的可用重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43879028/

相关文章:

ios - 如果启用了自动布局,则防止 UIScrollView 水平滚动

ios - 即使应用程序未在后台运行,如何使 iOS 应用程序执行一些代码?

ios - 如何在 Swift for iOS 应用程序中进行实时音频卷积?

ios - UITableViewController over-ride init 函数在使用 Storyboard时未被调用

ios - Swift 3.0中如何用代码控制Status Bar样式

ios - 重写drawRect : in UITableViewCell

xcode - iOS 应用仅通过耳机播放声音

ios - 如何在 iOS 5 Storyboard中初始化自定义原型(prototype)样式表格单元格?

ios - 切换到横向时,Tableview 将约束更改为全屏

ios - 没有更多上下文,表达式类型不明确。 <套接字引擎> 类