Any sample code like access view manager from uitabbarcontroller?

I'm new to iphone development

I created my storyboard with tabs and tabbaritems with their viewcontroller

but now I would like to access viewcontroller instances from my uitabbarcontroller.m

Does anyone have a url with sample code?

The codes I find are very simple to use or a scoreboard, basically just a storyboard that doesn't help anything ...

thanks

--- solution after using Muller

on uitabbarcontroller: (I placed a breakpoint and was able to get a collection of view controllers)

- (void)viewDidLoad { NSArray *arr = self.viewControllers; } 

+1
source share
1 answer

You can use something like

 NSArray *array = [tabBarControllerName viewControllers]; 

This returns an array of all the views in your tabBarController, so if your first view has a class, say TestView, we could do something like

 TestView *tv = (TestView *)[array objectAtIndex:0]; 

Please note that this is not OK, so this may be a bit. Make sure you look at the class reference materials that the apple provides: UITabBarController class reference

EDIT: you really can just single line:

 TestView *tv = (TestView *)[[tabBarControllerName viewControllers] objectAtIndex:0]; 

EDIT2: you can access the UITabBarController if it is declared in your AppDelegate application:

 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; TestView *tv = (TestView *)[[[appDelegate tabBarController] viewControllers] objectAtIndex:0]; 
+2
source

Source: https://habr.com/ru/post/1501074/


All Articles