How can it be done ?
I tried everything I could find on stack overflow and nothing worked for me. I would like a solution that will work like Instagram. If you scrolled down tap the TabBarItem
to go to the top .( I generally use tableviewControllers
and not view controllers if that matters the code)
Any help will be appreciated
In swift 2.2 thank you!
What i tried:
//Using the UiTabBarDelegate
class BarsViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate,UITabBarControllerDelegate,UITabBarDelegate{
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
if(item.tag == 1) {
//your code for tab item 1
tableView.scrollToTop(true)
}
else if(item.tag == 2) {
//your code for tab item 2
}
else if(item.tag == 4) {
//your code for tab item 4
self.tabBarItem.badgeValue = nil
tableView.scrollToTop(true) }
}
}
extension UITableView {
func scrollToTop(animated: Bool) {
setContentOffset(CGPoint.zero, animated: animated)
}
}