Properly declare delegation in Objective C (iPhone)

Posted by Gordon Fontenot on Stack Overflow See other posts from Stack Overflow or by Gordon Fontenot
Published on 2010-04-28T17:21:23Z Indexed on 2010/04/29 9:07 UTC
Read the original article Hit count: 364

Filed under:
|
|
|

Ok, This has been explained a few times (I got most of the way there using this post on SO), but I am missing something. I am able to compile cleanly, and able to set the delegate as well as call methods from the delegate, but I'm getting a warning on build:

No definition of protocol 'DetailViewControllerDelegate' is found

I have a DetailViewController and a RootViewController only. I am calling a method in RootViewController from DetailViewController. I have the delegate set up as so:

In RootViewController.h:

#import "DetailViewController.h"

@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate, DetailViewControllerDelegate> //Error shows up here
{
//Some Stuff Here
}
//Some other stuff here
@end

In RootViewController.m I define the delegate when I create the view using detailViewController.delegate = self

In DetailViewController.h:

@protocol DetailViewControllerDelegate;

#import "RootViewController.h"

@interface DetailViewController : UITableViewController <UITextFieldDelegate>
{
    id <DetailViewControllerDelegate> delegate;
}

@property (nonatomic, assign) id <DetailViewControllerDelegate> delegate;

@end

@protocol DetailViewControllerDelegate

//some methods that reside in RootViewController.m

@end

I feel weird about declaring the protocol above the import in DetailViewController.h, but if I don't it doesn't build. Like I said, the methods are called fine, and there are no other errors going on. What am I missing here?

© Stack Overflow or respective owner

Related posts about methods

Related posts about delegates