Reputation: 143
I am having UITabBarController
in which one of tab has two container view and I want to scroll to top on both controllers in it.
My Base View Controller is NotificationViewController
and child view controllers are like NotificationNetworkViewController
and NotificationPodcastViewController
I am Using following extension : -
extension NotificationNetworkViewController: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
print("Network TAB INDEX : \(tabBarController.selectedIndex)")
notificationTable.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
}
}
Upvotes: 0
Views: 81
Reputation: 281
Use the following code to achieve your needs. For animation, you just need to pass value true/false in animated of scrollToRow
function.
Hope this will help you!
To scroll top without animation
func scrollToBottomWithoutAnimation() {
DispatchQueue.main.async {
if self.dataArray.count > 0 {
let indexPath = IndexPath(row: 0, section: 0)
notificationTable.scrollToRow(at: indexPath, at: .top, animated: false)
}
}
}
To scroll top with animation
func scrollToBottomWithoutAnimation() {
DispatchQueue.main.async {
if self.dataArray.count > 0 {
let indexPath = IndexPath(row: 0, section: 0)
notificationTable.scrollToRow(at: indexPath, at: .top, animated: true)
}
}
}
Upvotes: 1