2

After searching on Internet, and in this forum I couldnt solve my problem.I`m making an app with a tab bar and three views managed with this tab bar(viewA, viewB, viewC). In one of the views (viewA) I have a button which I want to use to show one of the other two views(viewB) (but not with the button from the tab bar).

With this button I should call a function that switch from viewA to viewB, but the function is on the viewAcontroller.m, and from this controller I cant access to the tabBarController because I have defined it in the appDelegate.h.

Somebody knows how to get access to the tabBarController defined in the appDelegate.h, or another way to switch the views with a function from the viewAController.m?

Really thanks

yandrako
  • 41
  • 1
  • 3

1 Answers1

0

If you have a accessor of the tabBarController in the appDelegate.h, you can try this: [(appDelegate *)[UIApplication sharedApplication].delegate tabBarController]


You should have a class named XXXAppDelegate, with a XXXAppDelegate.h and a XXXAppDelegate.m In the XXXAppDelegate.h it likes like this:

    @interface XXXAppDelegate : NSObject <UIApplicationDelegate>
    {
        XXXViewController *viewAcontroller;
    }

    // Add this line
    @property (assign) XXXViewController *viewAcontroller;

    @end

in the XXXAppDelegate.m

Add a line under your @implementation XXXAppDelegate

@synthesis viewAcontroller;

Then use this line to get a reference to your tabBarController [(XXXAppDelegate *)[UIApplication sharedApplication].delegate tabBarController]

mr.pppoe
  • 3,945
  • 1
  • 19
  • 23
  • It could be, but if i try to write (appDelegate*) in the viewAController it doesnt work. I supose that I have to defined this but dont know where and how, could you explain it how to use this accesor please? or where i could learn? I'm not sure i'm understanding the accesor. Sorry, i'm quite new in ios dev. – yandrako Apr 27 '11 at 15:58
  • Please refer to the lines above, hope this help. – mr.pppoe Apr 28 '11 at 05:53
  • Really thanks!! Finally I solve my problem thanks to your answer. Sincerely, i dont understand completely what i'm doing, but I imagine that is a type of reference to the delegate that the controller make to acces to their controllers, etc. Thanks again!! – yandrako Apr 28 '11 at 16:38