nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
I'm receiving error "Cannot find protocol declaration for CheckmarkDelegate" in ContentAViewController.h. Why is this?

QuizTableViewController.h
Code:
#import <UIKit/UIKit.h>
#import "ContentAViewController.h"

@protocol CheckmarkDelegate <NSObject>
@required
- (void) processSuccessful: (BOOL)success;

@end

@interface QuizTableViewController : UITableViewController
{
    id <CheckmarkDelegate> delegate;
}

@property (retain) id delegate;

@end

QuizTableViewController.m
Code:
#import "QuizTableViewController.h"

@implementation QuizTableViewController
@synthesize delegate;

- (void) processComplete
{
    [self.delegate processSuccessful:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView reloadData];
}

ContentAViewController.h
Code:
#import <UIKit/UIKit.h>
#import "QuizTableViewController.h"

@interface ContentAViewController : UIViewController <CheckmarkDelegate>

@end

ContentAViewController.m
Code:
#import "ContentAViewController.h"

@implementation ContentAViewController

- (void) processSuccessful: (BOOL) success
{
    NSLog(@"Process Succesful");
}

- (IBAction)OK:(id)sender 
{
    if ([answerAVal.text isEqualToString:@"CORRECT!"])
    {
        [self processSuccessful:YES];
    } else {
        
    [self dismissModalViewControllerAnimated:YES];
    }
}
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Because QuizTableViewController.h is importing ContentAViewController.h.


Think about what happens when the compiler comes to compiling QuizTableViewController.m.

The first thing it encounters is #import "QuizTableViewController.h". So basically, that line is replaced with the contents of QuizTableViewController.h and compilation effectively continues with the first line of QuizTableViewController.h.

The second thing that happens is UIKit/Kit.h is imported in the same way.

The third thing that happens is #import "ContentAViewController.h" again in the same way.

Effectively we're now at the first line of "ContentAViewController.h. The #import <UIKit/UIKit.h> does nothing because UIKit/UIKIt.h has already been imported.

The #import "QuizTableViewController.h" is also ignored because QuizTableViewController.h has already (is being) imported.

Then the compiler get to the @interface ContentAViewController line in QuizTableViewController.h which references CheckmarkDelegate, but as you can see the compiler has never seen the @protocol CheckmarkDelegate at that point. So it complains.


For what you've posted, there's not need for QuizTableViewController.h to import ContentAViewController.h, so take it out.
 

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
Confused

Because QuizTableViewController.h is importing ContentAViewController.h.


Think about what happens when the compiler comes to compiling QuizTableViewController.m.

The first thing it encounters is #import "QuizTableViewController.h". So basically, that line is replaced with the contents of QuizTableViewController.h and compilation effectively continues with the first line of QuizTableViewController.h.

The second thing that happens is UIKit/Kit.h is imported in the same way.

The third thing that happens is #import "ContentAViewController.h" again in the same way.

Effectively we're now at the first line of "ContentAViewController.h. The #import <UIKit/UIKit.h> does nothing because UIKit/UIKIt.h has already been imported.

The #import "QuizTableViewController.h" is also ignored because QuizTableViewController.h has already (is being) imported.

Then the compiler get to the @interface ContentAViewController line in QuizTableViewController.h which references CheckmarkDelegate, but as you can see the compiler has never seen the @protocol CheckmarkDelegate at that point. So it complains.


For what you've posted, there's not need for QuizTableViewController.h to import ContentAViewController.h, so take it out.

Still doesn't work.
Getting depressed.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.