I have a UITabBarController and 4 UITabBarItem. I want to navigate through them programmatically. I'm looking forward on how to do it.. (Swift)
Asked
Active
Viewed 305 times
0
-
What did you try to do? i.e where is your code snippet? – Ahmad F Dec 13 '16 at 09:00
-
There are many answers about this topic, I assume [this answer](http://stackoverflow.com/a/40111462/5501940) should be useful to your case. – Ahmad F Dec 13 '16 at 09:05
1 Answers
0
self.tabBarController?.selectedIndex = 0 //1, 2 or 3

lithium
- 1,272
- 1
- 14
- 28
-
override func viewWillAppear(_ animated: Bool) { if loadViewAtTabIndex != -1 { tabBarController?.selectedIndex = 1 loadViewAtTabIndex = -1 } self.pullDataFromSourceAndUpdateUI() } – Mahil Arasu Dec 13 '16 at 09:08
-
i did add the above code what you told in the viewWillAppear method. Even though the lines are executed, the preferred tab is not shown – Mahil Arasu Dec 13 '16 at 09:10
-
I don't know what is "loadViewAtTabIndex" here (maybe, it equals -1 in your case) but I'd try to put just one line in viewDidLoad or viewDidAppear. Also, if you update your question with code of your viewController it'd much simpler for me or others to help you. – lithium Dec 13 '16 at 09:16