【iOS】self.tabBarController.selectedIndex 和 self.selectedIndex

今天自己犯了一个低级的错误,self.tabBarController.selectedIndex = 1;  方法设置了去没有效果,并且一直找不到原因,Why? 后来发现设置的类继承自UITabBarController,需要用 self.selectedIndex = 1; 设置。

两者的区别:

在继承自UITabBarController的类中使用self.selectedIndex

例如:@interface XX : UITabBarController

在继承自UIViewController、UINavigationController或其他的Controller中使用self.tabBarController.selectedIndex

例如:@interface XX :UIViewController

你可能感兴趣的:(【iOS】self.tabBarController.selectedIndex 和 self.selectedIndex)