1
votes

I'm new with iphone development

I created my storyboard with tabbar and tabbaritems with their viewcontroller

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

anybody have any url with code example?

the codes I find are very simple use or tabbar, mostly just the storyboard which doesn't help in anything...

thanks

---solution after help from Muller

on the uitabbarcontroller:(I placed a breakpoint and was able to retrieve the collection of viewcontrollers)

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

1

1 Answers

2
votes

You could use something like

NSArray *array = [tabBarControllerName viewControllers];

This returns an array of all the views within your tabBarController, so if your first view is of class, let's say TestView we could do something like

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

Note that this is off the top of my head, so it may be a little off. Make sure you check out the class reference materials that apple provides: UITabBarController Class Reference

EDIT: You could really just one-line it like this:

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

EDIT2: You can access the UITabBarController if it is declared in your AppDelegate by:

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