Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ppn

macrumors member
Original poster
Oct 31, 2010
36
0
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.

PHP:
@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
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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

macrumors member
Original poster
Oct 31, 2010
36
0
My MainViewController looks like this:

PHP:
#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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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

macrumors member
Original poster
Oct 31, 2010
36
0
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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
There are many examples of @protocols in the UIKit headers. See for example

Code:
@protocol UIScrollViewDelegate<NSObject>

or just find in frameworks:

Code:
@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

macrumors member
Original poster
Oct 31, 2010
36
0
I've declared my FlipsideViewControllerDelegate in my FlipsideViewController.h file. I used @protocol FlipsideViewControllerDelegate. You mean I have to declare it somewhere else?
 

ppn

macrumors member
Original poster
Oct 31, 2010
36
0
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

macrumors 68040
Sep 2, 2008
3,114
93
A full definition of a protocol looks something like this

Code:
@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

macrumors member
Original poster
Oct 31, 2010
36
0
Thanks Guys, it turns out i left out the last part of my code when I copied the file over.

PHP:
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.