ios - 滚动到 UITableView 的底部(UITableView 在 UITableViewCell 中)

标签 ios iphone swift uitableview

加载完成后,如何滚动到 UITableView 的底部?

UITableView 位于 UITableViewCell 中,UITableViewCell 位于 UItableView 本身中。

所以: UITableView --> UITableViewCell --> UITableView(滚动到此处底部)

这会崩溃:

func reloadData(){
    if (neighbourhoodJoined){
        messageInputView.hidden = false
        chatroomMessagesListReversed = chatroomMessagesList.reverse() as! [ChatroomMessage]
        chatroomTableView.reloadData()
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            var iPath = NSIndexPath(forRow: self.chatroomTableView.numberOfRowsInSection(0)-1,
                inSection: self.chatroomTableView.numberOfSections-1)
            self.chatroomTableView.scrollToRowAtIndexPath(iPath,
                atScrollPosition: UITableViewScrollPosition.Bottom,
                animated: true)
        })
    } 
}

最佳答案

你可以喜欢这样:

if (tableView.contentSize.height > tableView.frame.size.height)
{
  tableView.setContentOffset(CGPointMake(0, tableView.contentSize.height - tableView.frame.size.height), animated: true)
}

关于ios - 滚动到 UITableView 的底部(UITableView 在 UITableViewCell 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38949246/

相关文章:

iphone - iPhone 应用程序中的文件数量有限制吗?

iphone - 可滚动的网格状 View

html - 网站在 iPhone 上旋转 180 度

iphone - 通过应用程序 ID 生成 iTunes 应用程序图标 URL

swift - 如何使 Swift NSComboBox 每行从多维数组返回一个数组

swift - Swift 中的隐式类型转换

swift - 如何在 swift 中创建一个 SKViaPoint 数组 - Skobbler API

iphone - 如何存储所有这些预先创建的数据?

ios - iOS-如何处理文件名中的空格

iphone - 如何将图像放入 iPad 上的 UIImagePickerController