In an app I\'m working on, I have a plain style UITableView that can contain a section containing zero rows. I want to be able to scroll to this section using scrollToRowAtI
A Swift approach to the same:
if rows > 0 {
let indexPath = IndexPath(row: 0, section: section)
self.tableView.setContentOffset(CGPoint.zero, animated: true)
self.tableView.scrollToRow(at: indexPath, at: .top, animated: true)
}
else {
let sectionRect : CGRect = tableView.rect(forSection: section)
tableView.scrollRectToVisible(sectionRect, animated: true)
}