Scroll to particular row in tableView iOS swift
Problem:
I want to create a table view after fetch data from server want to update the tableview then scroll to particular row
Solution:
Use the below code to achieve that scroll..
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
if self.myTV.hasRow(at: IndexPath(arrayLiteral: indexofsection)) {
self. myTV.scrollToRow(at: IndexPath(row: 0, section: indexofsection), at: .top, animated: true)
}
}
Use the extension
extension UITableView {
func hasRow(at indexPath: IndexPath) -> Bool {
return indexPath.section < self.numberOfSections
}
}
Comments
Post a Comment