PDA

View Full Version : no definition of protocol 'FlipsideViewControllerDelegate' is found




ppn
Jan 9, 2011, 07:10 PM
Hey Guys,

I'm using the utility template where they have a FlipsideViewControllerDelegate. But my MainViewController keeps giving me a warning for no definition of protocol 'FlipsideViewControllerDelegate' is found but I've clearly defined it in my FlipsideViewController. Any ideas? I copied this code from my old app and it works fine in the old app so I don't know why it's giving me that warning.

@protocol FlipsideViewControllerDelegate;

@interface FlipsideViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
id <FlipsideViewControllerDelegate> delegate;
NSArray *options;
IBOutlet UILabel *description;
IBOutlet UILabel *answers;
IBOutlet UILabel *status;
IBOutlet UIPickerView *pickerView;
NSInteger correct;
NSInteger incorrect;
NSInteger notAttempted;
NSInteger preference;
NSManagedObjectContext *managedObjectContext_;
}

@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
@property (nonatomic, retain) UILabel *description;
@property (nonatomic, retain) UILabel *answers;
@property (nonatomic, retain) UILabel *status;
@property (nonatomic, retain) UIPickerView *pickerView;
@property (nonatomic, assign) NSInteger correct;
@property (nonatomic, assign) NSInteger incorrect;
@property (nonatomic, assign) NSInteger notAttempted;
@property (nonatomic, assign) NSInteger preference;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext_;
- (IBAction)done:(id)sender;
- (IBAction)resetHistory:(id)sender;
- (void)saveOptions;
- (void)loadOptions;
- (void)countStatus;
- (void)updateStatus;
- (void)displayDescription:(NSInteger)row;
- (void)saveContext;
@end



dejo
Jan 10, 2011, 09:52 AM
But my MainViewController keeps giving me a warning for no definition of protocol 'FlipsideViewControllerDelegate' is found...
Can you show us what your MainViewController.h looks like?

PhoneyDeveloper
Jan 10, 2011, 10:08 AM
If you preprocess a source code file you end up with a file that is exactly what the compiler sees. Inspection of the preprocessed file will often help to figure out problems like this. Use the Build > Preprocess menu item for your FlipsideViewController.m file.

ppn
Jan 10, 2011, 03:49 PM
My MainViewController looks like this:

#import "FlipsideViewController.h"
#import "QuizViewController.h"
#import "LessonTableViewController.h"
#import "BCRoadTestAppDelegate.h"
#import "Quiz.h"
#import <CoreData/CoreData.h>

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, QuizViewControllerDelegate, LessonTableViewControllerDelegate> {
NSManagedObjectContext *managedObjectContext_;
NSInteger counter;
NSMutableArray *quizzes;
Quiz *currentQuiz;
}

@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext_;
@property (nonatomic, assign) NSInteger counter;
@property (nonatomic, retain) NSMutableArray *quizzes;
@property (nonatomic, readonly) Quiz *currentQuiz;

- (void)saveContext;
//- (void)updateDatabase;
- (void)createEditableCopyOfDatabaseIfNeeded;
- (IBAction)showInfo:(id)sender;
- (IBAction)loadQuiz:(id)sender;
- (IBAction)loadLessonTableViewController:(id)sender;

@end


I have no problem running the project and even the FlipsideViewController works fine. The only problem I see is in my FlipsideViewController.h file. In the line "id <FlipsideViewControllerDelegate> delegate;", the FlipsideViewControllerDelegate isn't in light blue but in my other files, all the Delegates are in light blue once I declare them a protocol. I copied this header from another project and it was in light blue in the other project. I have no idea why it's not picking it up.

dejo
Jan 10, 2011, 04:01 PM
The only problem I see is in my FlipsideViewController.h file.
I'm confused. I thought the problem was with your MainViewController.

PhoneyDeveloper
Jan 10, 2011, 04:03 PM
The compiler is right. You haven't defined this delegate protocol. What you've done is forward declare it. You need a full definition of it.

ppn
Jan 10, 2011, 04:04 PM
It is. That's where the warning is showing up so I look into the FlipsideViewController and I notice the FlipsideViewControllerDelegate isn't highlighted in light blue so I'm guessing that's why it's telling me it can't find the FlipsideViewControllerDelegate.

ppn
Jan 10, 2011, 04:04 PM
The compiler is right. You haven't defined this delegate protocol. What you've done is forward declare it. You need a full definition of it.

O, what does that mean? How would I do a full definition?

PhoneyDeveloper
Jan 10, 2011, 04:10 PM
There are many examples of @protocols in the UIKit headers. See for example

@protocol UIScrollViewDelegate<NSObject>

or just find in frameworks:

@protocol

What methods do you want to be in your protocol?

Also, you should know the definitions for "declaration" and "definition" in this context.

ppn
Jan 10, 2011, 04:13 PM
I've declared my FlipsideViewControllerDelegate in my FlipsideViewController.h file. I used @protocol FlipsideViewControllerDelegate. You mean I have to declare it somewhere else?

dejo
Jan 10, 2011, 04:17 PM
No, you have to define it.

ppn
Jan 10, 2011, 04:19 PM
I'm sorry, I'm still pretty new at this. So in which file should I define it? Is defining just simply writing @protocol FlipsideViewControllerDelegate in my FlipsideViewController.h file or do I need to define it somewhere else too?

PhoneyDeveloper
Jan 10, 2011, 04:40 PM
A full definition of a protocol looks something like this

@protocol UIScrollViewDelegate<NSObject>

@optional

- (void)scrollViewDidScroll:(UIScrollView *)scrollView; // any offset changes
- (void)scrollViewDidZoom:(UIScrollView *)scrollView __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // any zoom scale changes

// etc...

@end


You need all that stuff.

What you have is a forward declaration. It tells the compiler that there exists a protocol with the specified name but that the declaration is somewhere else. The compiler can do some things without the full definition of the protocol but it has to have it someplace if you want the protocol to mean anything. When you tell the compiler that a class conforms to a protocol it needs to know the definition of the protocol so it can give you errors or warnings about whether the class really conforms.

ppn
Jan 10, 2011, 06:00 PM
Thanks Guys, it turns out i left out the last part of my code when I copied the file over.

@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end