Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access the viewControllers on the UITabbarController in swift?

I'm trying to get the 2nd viewcontroller of the tabbarcontroller so i can popToRoot but Swift tells me that using an Int as a subscript is not valid and I have to use an AnyObject as an index

var controller = self.viewControllers[2] as! UIViewController

error is "Cannot subscript a value of type [AnyObject]? with an Int"

like image 452
angel of code Avatar asked Dec 20 '22 01:12

angel of code


1 Answers

var controller = self.viewControllers![2] as! UIViewController
like image 169
liushuaikobe Avatar answered May 14 '23 09:05

liushuaikobe