How to scroll to the bottom of a UITableView on the iPhone before the view appears
I believe that calling
tableView.setContentOffset(CGPoint(x: 0, y: CGFloat.greatestFiniteMagnitude), animated: false)
will do what you want.
Scroll table view to bottom when using dynamic cell height
Eventually, I have found the answer. The reason why scrolling to the bottom does not work (and inserting/deleting rows are buggy as well, as I found out later), is because cell height is not properly estimated
. To get around this, try to return close estimations in estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
. However, if you can't do that (and in most cases you won't be able to) there is still a great solution: Store the heights of the cells in a dictionary, and return those for the estimatedHeight
when cells are reused (e.g. table view is scrolled). I have found this solution in another question, so please go and check that out for the actual code on how you would carry this out. (although probably, many of you can write this for themselves)
Original solution by @dosdos
EDIT: Maybe to fix just scrolling to the bottom this is unnecessary, however highly recommended in my opinion. If you don't use this for estimating your row height, you will encounter other problems such as buggy scrolling and worse performance at a large number of cells.
Also you need to add this to viewDidAppear
let lastItem = IndexPath(item: dataSource.count - 1, section: 0)
tableView.scrollToRow(at: lastItem, at: .bottom, animated: true)
Detect when UITableView has scrolled to the bottom
Swift 3
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row + 1 == yourArray.count {
print("do something")
}
}
Related Topics
How to Trap on Uiviewalertforunsatisfiableconstraints
How to Create IPA in Xcode 6 Without Apple Developer Account
How to Use Iboutletcollection to Connect Multiple Uiimageviews to the Same Outlet
Static Table View Outside Uitableviewcontroller
How to Add Unique Constraints for Some Fields in Core Data
iPhone Sdk Cgaffinetransform Getting the Angle of Rotation of an Object
Uiscrollview: Paging Horizontally, Scrolling Vertically
Resize Uiimage to 200X200Pt/Px
Ios: Copy a File in Documents Folder
Strange Generic Function Appear in View Controller After Converting to Swift 3
How to Test If a String Is Empty in Objective-C
How to Convert a String to an Md5 Hash in iOS Using Swift
Xcode Nsmanagedobject Subclass Contains Optionals When They Are Marked as Non-Optional
Presenting a Uialertcontroller Properly on an iPad Using iOS 8
How to Make an Uipickerview Component Wrap Around
Xcode Quits Unexpectedly Every Time I Open My Project
Cocoapods - 'Pod Install' Takes Forever
How to Obtain a Dynamic Table View Section Header Height Using Auto Layout