How can i set an action
for my UITabBarItem
? Can i connect it from storyboard
to code somehow? or programmatically? And if so how can it be done?
My hierarchy is UITabBarController
-> UINavigationController
-> UITabBarItem
Sorry for the noobish question but i really need an answer for this. And I couldn't find anything regarding this online.
Using Swift 3 and Xcode 8
Thank you!
i tired Mannopson's Answer (didn't work):
class BarsViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate,UITabBarControllerDelegate{
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarController?.delegate = self
}
func tabBarController(tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if viewController.tabBarItem.tag == 1 {
self.tableView.setContentOffset(.zero, animated: true)
}
}
}
extension UITableView {
func scrollToTop(animated: Bool) {
setContentOffset(CGPoint.zero, animated: animated)
}
}
silentBob Answer Didn't Work for me :
class BarsViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate,UITabBarControllerDelegate{
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarController?.delegate = self
}
func tabBarController(tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if viewController.tabBarItem.tag == 1 {
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: .Top, animated: true)
}
}
}
i also tried Tushar Sharma's answer and it didn't work as well.
What Im trying to do is when you are scrolled down in the tableView
you will tap the current Tabbaritem
the tableView Will scroll to top just like intagram.