I am trying to get the selected tabbarController index.
let application = UIApplication.sharedApplication().delegate as AppDelegate let tabbarController = application.tabBarController as UITabBarController let selectedIndex = tabBarController.selectedIndex
I get this error: 'UITabBarController?' does not have a member named 'selectedIndex'
'UITabBarController?' does not have a member named 'selectedIndex'
Did I miss something?
application.tabBarControlleris optional, which means it can be nil. If you are sure you will never nil, do the following:
application.tabBarController
nil
var selectedIndex = tabBarController!.selectedIndex
you should try the following:
let application = UIApplication.shared.delegate as! AppDelegate let tabbarController = application.window?.rootViewController as! UITabBarController let selectedIndex = tabbarController.selectedIndex
Source: https://habr.com/ru/post/1016162/More articles:how a static variable does not get reassigned when inside the function - cApple reports application crash, but I can't figure it out - iosopening angular application pages in sequence - second call to page.open not called - javascriptHow to set tab bar icon fast? - iosDo C # properties always have backstage backup fields? - c #DBI reconnection does not work with lexical variable in Perl 5.24.0 - scopeHow to put lambda expression after parameters on mapTo to call legal syntax? - lambdaFind out if a business is open in T-SQL - sqlWhy use wrappers around actual iterator functions in LINQ extension methods? - iteratormatching native hibernate queries - javaAll Articles