iphone - Swapping views in a tab bar app calling the view controller directly and not by its index -
i want swap views in tab bar application can't rely on index of view controllers change. cannot use code below:
[self.tabbarcontroller setselectedindex:4]; i want able call specific view controller name. how can please?
thanks
you can select view controller of specific class using code:
nsuinteger index = [self.tabbarcontroller.viewcontrollers indexofobjectpassingtest:^bool(id obj, nsuinteger idx, bool *stop) { return [obj iskindofclass:[classofviewcontrolleryouarelookingfor class]]; }]; if(index != nsnotfound) { [self.tabbarcontroller setselectedindex:index]; } or can select specific viewcontroller instance using code:
nsuinteger index = [self.tabbarcontroller.viewcontrollers indexofobject:yourviewcontroller]; if(index != nsnotfound) { [self.tabbarcontroller setselectedindex:index]; }
Comments
Post a Comment