views:

39

answers:

2

Hi all,
I'm working on an application with three tabs plus a small view in which I created a sort of TopBar that contains some info and some buttons.

In the main application delegate I define:

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{  
  ...
  // Add the tab bar controller's current view as a subview of the window  
  [window addSubview:tabBarController.view];  
  //here we add the topBar:  
  topBarViewController = [TopBarViewController instance];  
  topBarViewController.appDelegate = self;
  [window addSubview:topBarViewController.view];
  ...
}

- (void)showReplyView
{
  self.tabBarController.selectedViewController = 
    [self.tabBarController.viewControllers objectAtIndex:2];
}

as you can see I set the .appDelegate in the topBar to make some call back in the code of the topBar (ie: when I want to change the tab currently visualized)

Now in my TopBarViewController.h I have:

@interface TopBarViewController : UIViewController {
  MyAppDelegate *appDelegate;
  ...
}
@property (nonatomic,retain) MyAppDelegate *appDelegate;
-(void)testMethod;

and in the .m file:

@implementation TopBarViewController
@synthesize appDelegate;
...
-(void)testMethod{
  [appDelegate showReplyView];
}
...

When I build the project the compiler tell me that the showReplyView method doesn't exist. I tried everything and I'm sure that there are no typo errors...

Is it possible that I can't reference to the delegate? Thanks to anyone would help me...

+1  A: 

Have you defined showReplyView in the @interface for MyAppDelegate?

Marcelo Cantos
+2  A: 

I found the problem: in the TopBarViewController.h I was declaring @class MyAppDelegate; since I couldn't make an import (avoid the loop). So the compiler was not able to find out which methods were declared.

To solve it I import the #import MyAppDelegate.h directly in the TopBarViewController.m!

Thanks anyway for the help!

enrico