简体   繁体   中英

Scrolling to bottom of UITableView (UITableView is in a UITableViewCell)

How do I scroll all the way to the bottom of a UITableView when it is done loading?

The UITableView is located in a UITableViewCell and the UITableViewCell is located in a UItableView itself.

So: UITableView --> UITableViewCell --> UITableView (scroll to the bottom here)

This is crashing:

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

you can like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM