滚动到UITableView的底部(UITableView位于UITableViewCell中)

时间:2016-08-15 04:15:07

标签: 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)
        })
    } 
}

1 个答案:

答案 0 :(得分:0)

你可以这样:

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