If this is not obvious by name, then I want to be simple, as it tableViewwill begin to scroll to the lowest level when users first see it ( before it sees it, and without animation ).
So, I know that this has been answered several times, but none of these solutions seem to be working right now. To give some context, I use Swift, autorun, and the latest version of iOS to date.
Limitations
There are several things that I need to support:
- download it before the user sees it (without animation, obviously).
- dynamic cell heights, i.e. their height is determined by UILabel (for example, a messaging application - using autorun in a storyboard).
- My
UITableViewis inside UIScrollView( UIScrollViewscrolls horizontally and UITableViewscrolls vertically). UITableViewlocated in childViewController, i.e. I add it to the main one UIViewController(which for some reason does viewWillAppearnot get called - viewDidAppearis still being called).
I will do a summary of what I tried:
As for the implementations:
tableView.contentOffset = CGPoint(x: 0, y: CGFloat.max
tableView.scrollToRowAtIndexPath(indexPathForLastItem, atScrollPosition: .Bottom, animated: false)
var contentOffset = tableView.contentOffset
contentOffset.y = tableView.contentSize.height - tableView.bounds.size.height
tableView.setContentOffset(contentOffset, animated: false)
dispatch_async(dispatch_get_main_queue(), {
})
As for the places that I tried to call these implementations:
viewDidLoadviewWillAppearviewDidLayoutSubviews (only the first time he called, I use the property to track this)viewDidAppear (although this will not give me what I want)- On my model
didSet
Before what I always called tableView.reloadData
What I do NOT want to do:
tableView.transform = CGAffineTransformMakeScale(1, -1)
+
cell.transform = CGAffineTransformMakeScale(1, -1)
( , , , , , . , , , )
, , ...
, :
tableView contentSize ( UIScrollView) . , contentSize, contentOffset, . tableView .- , (, , - ), 20 .
viewWillAppear , viewDidAppear .
( , ) . , .
, scrollToRowAtIndexPath... , .. , , , 2000 . , .
:
@bsmith11 :
private var called = false
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if !called {
dispatch_async(dispatch_get_main_queue(), {
self.tableView.setContentOffset(CGPoint(x: 0, y: self.tableView.bounds.height), animated: false)
})
called = true
}
}
.