Skip to content

Instantly share code, notes, and snippets.

@0xWDG
Created January 16, 2017 21:04
Show Gist options
  • Save 0xWDG/3f1d3785a9b5010223d52407fb236108 to your computer and use it in GitHub Desktop.
Save 0xWDG/3f1d3785a9b5010223d52407fb236108 to your computer and use it in GitHub Desktop.
Read UITabbar title and activate that screen
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