Created
January 16, 2017 21:04
-
-
Save 0xWDG/3f1d3785a9b5010223d52407fb236108 to your computer and use it in GitHub Desktop.
Read UITabbar title and activate that screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
class testVC: UIViewController { | |
/* | |
Using this in your first active UITabBar screen, will allow you to change the screen for e.g. a Quick Action. | |
*/ | |
var freshLaunch = true | |
override func viewWillAppear(_ animated: Bool) { | |
//Use viewWillAppear (instead of) viewDidAppear to prevent a screen flicker | |
if freshLaunch == true { | |
freshLaunch = false | |
var idx = 0 | |
for vc in (super.tabBarController?.viewControllers)! { | |
if let title = vc.tabBarItem.title { | |
print("\(title) is unwrapped") | |
if (title == "Debug") { // Change the screen you want to activate | |
print("Activating \(title)") | |
super.tabBarController?.selectedIndex = idx | |
return | |
} | |
} | |
idx += 1 | |
} | |
} | |
super.viewDidAppear(animated) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment