0

I am making an app with 4 tabbar items. one of them has a WebView and on the website there are buttons that go to other things on the website or to an other website but how can I make it that if I press the tab bar item again that it goes back to the first view (like the app store when you press the tab bar item again you go back to the beginning). when I try to add a insert a action I can only choose between make an outlet or an outlet collection.

only outlet and outlet collection image

thanks for reading this, I hope I gave enough information to understand my quistion.

TimeParadox
  • 169
  • 2
  • 12
  • Take a look at `UITabBarControllerDelegate` https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarControllerDelegate_Protocol/#//apple_ref/occ/intfm/UITabBarControllerDelegate/tabBarController:shouldSelectViewController: – tbilopavlovic Jun 17 '16 at 14:42
  • A `UIBarButtonItem` should allow you to add an action I've just tested it. – arled Jun 17 '16 at 14:57
  • I have added an picture, I don't see action... only outlet and outlet collection – TimeParadox Jun 17 '16 at 15:16

2 Answers2

1

I found the answer!

first I ran the code in the viewdidload but in the viewdidload code only loads (runs) one time so if you want to run it every time you go to the tabbar you need to paste the same code inside the viewwillappear:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
}

if you run your code in the viewWillAppear than it will load every time you go to the tabbar

I hope this helps the people that also have this question.

TimeParadox
  • 169
  • 2
  • 12
  • This helped me with the same issue. Sometimes the simplest answers are the best ones! Thanks! – adman Sep 27 '16 at 05:21
0

Referring to this answer

" You should use UITabBarDelegate with method didSelectItem. Use it as any standard delegate:

class yourclass: UIViewController, UITabBarDelegate {
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
    //This method will be called when user changes tab.
}
}

And do not forget to set your tab bar delegate to self in view controller. "

Hope it helps!

Community
  • 1
  • 1
Tung Fam
  • 6,494
  • 4
  • 48
  • 55