no definition of protocol 'FlipsideViewControllerDelegate' is found

Discussion in 'iOS Programming' started by ppn, Jan 9, 2011.

  1. ppn
    macrumors member

    Joined:
    Oct 31, 2010
    #1
    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 <UIPickerViewDelegateUIPickerViewDataSource> {
        
    id <FlipsideViewControllerDelegatedelegate;
        
    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 (nonatomicassignid <FlipsideViewControllerDelegatedelegate;
    @
    property (nonatomicretainUILabel *description;
    @
    property (nonatomicretainUILabel *answers;
    @
    property (nonatomicretainUILabel *status;
    @
    property (nonatomicretainUIPickerView *pickerView;
    @
    property (nonatomicassignNSInteger correct;
    @
    property (nonatomicassignNSInteger incorrect;
    @
    property (nonatomicassignNSInteger notAttempted;
    @
    property (nonatomicassignNSInteger preference;
    @
    property (nonatomicretainNSManagedObjectContext *managedObjectContext_;
    - (
    IBAction)done:(id)sender;
    - (
    IBAction)resetHistory:(id)sender;
    - (
    void)saveOptions;
    - (
    void)loadOptions;
    - (
    void)countStatus;
    - (
    void)updateStatus;
    - (
    void)displayDescription:(NSInteger)row;
    - (
    void)saveContext;
    @
    end
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Can you show us what your MainViewController.h looks like?
     
  3. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    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.
     
  4. ppn
    thread starter macrumors member

    Joined:
    Oct 31, 2010
    #4
    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 <FlipsideViewControllerDelegateQuizViewControllerDelegateLessonTableViewControllerDelegate> {
        
    NSManagedObjectContext *managedObjectContext_;
        
    NSInteger counter;
        
    NSMutableArray *quizzes;
        
    Quiz *currentQuiz;
    }

    @
    property (nonatomicretainNSManagedObjectContext *managedObjectContext_;
    @
    property (nonatomicassignNSInteger counter;
    @
    property (nonatomicretainNSMutableArray *quizzes;
    @
    property (nonatomicreadonlyQuiz *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.
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    I'm confused. I thought the problem was with your MainViewController.
     
  6. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    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.
     
  7. ppn
    thread starter macrumors member

    Joined:
    Oct 31, 2010
    #7
    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.
     
  8. ppn
    thread starter macrumors member

    Joined:
    Oct 31, 2010
    #8
    O, what does that mean? How would I do a full definition?
     
  9. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    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.
     
  10. ppn
    thread starter macrumors member

    Joined:
    Oct 31, 2010
    #10
    I've declared my FlipsideViewControllerDelegate in my FlipsideViewController.h file. I used @protocol FlipsideViewControllerDelegate. You mean I have to declare it somewhere else?
     
  11. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  12. ppn
    thread starter macrumors member

    Joined:
    Oct 31, 2010
    #12
    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?
     
  13. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #13
    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.
     
  14. ppn
    thread starter macrumors member

    Joined:
    Oct 31, 2010
    #14
    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
     

Share This Page