Duplicate protocol definition - iphone

Getting warning message that Duplicate protocol definition of ModalViewDelegate is ignored
Defined protocol in modalviewcontroller.h file
#protocol ModalViewDelegate;
-(void)dismissView:(id)sender;
#interface Modalviewcontroller : UIViewController
{
id<ModalViewDelegate>delegate;
}
#property (nonatomic, assign) id<ModalViewDelegate>delegate;
#end
In the Modalviewcontroller.m file synthesize delegate
In Mainviewcontroller.h file
#protocol ModalViewDelegate
-(void)didDismissModal:(id)sender;
#end
#interface Mainviewcontrollerontroller : UIViewController <ModalViewDelegate>
-(void)showModal:(id)sender;
In the Mainviewcontroller.m not synthesize delegate
Am I supposed to delegate in mainviewcontroller.m file too?
Why I'm getting warning message of duplicate protocol definition?

Try to remove #protocol ModalViewDelegate; in modalviewcontroller.h and import Mainviewcontroller.h in this file.

You are defining the protocol twice one in mainviewcontroller.h and the other in modalViewController.h...thats why you are getting the warning...

Related

Cocos2d ,need to include protocol in my implementation file

So basically I have a protocol inside my interface that I need to include in my implementation because I am getting an incomplete error and therefore can't continue.
. h file
#interface waveLayer1 : CCLayer <GameKitHelperProtocol>
{
...
}
.m file
#implementation waveLayer1
GameKitHelper.h file
#import "cocos2d.h"
#import <GameKit/GameKit.h>
#protocol GameKitHelperProtocol
-(void) onLocalPlayerAuthenticationChanged;
-(void) onFriendListReceived: (NSArray*)friends;
-(void) onPlayerInfoReceived:(NSArray*)players;
#end
#interface GameKitHelper : NSObject {
id<GameKitHelperProtocol> delegate; bool isGameCenterAvailable; NSError* lastError;
}
#property (nonatomic, retain) id<GameKitHelperProtocol> delegate;
#property (nonatomic, readonly) bool isGameCenterAvailable; #property (nonatomic, readonly) NSError* lastError;
+(GameKitHelper*) sharedGameKitHelper;
// Player authentication, info
-(void) authenticateLocalPlayer;
-(void) getLocalPlayerFriends;
-(void) getPlayerInfo:(NSArray*)players;
#end
The error is "Method in protocol not implemented" I have more files I can show ,but to save room I decided to see if you can help me fix this with just these codes
#interface waveLayer1 : CCLayer <GameKitHelperProtocol>
This says that "wavelayer1" implements the protocol "GameKitHelperProtocol".
Method in protocol not implemented
says that a method declared in a protocol has not been implemented. Chances are that you forgot to implement one of the "GameKitHelperProtocol" methods, which makes your class NOT implement that protocol, which violates the declaration you made, which causes the compiler to output an error.
Implement these 3 methods in your waveLayer1 class..
-(void) onLocalPlayerAuthenticationChanged;
-(void) onFriendListReceived:(NSArray*)friends;
-(void) onPlayerInfoReceived:(NSArray*)players;
When you declare that a class adopts a protocol, you must write an implementation for all required methods that are defined in that protocol. So in this case, you need to add method implementations that are defined in GameKitHelperProtocol.

Protocol declaration warning

MPPopoverControllerDelegate.h file
#import <Foundation/Foundation.h>
#class MPPopoverController;
#protocol MPPopoverControllerDelegate <NSObject>
#optional
- (void)popoverControllerDidDismissPopover:(MPPopoverController *)popoverController;
#end
MPPopoverController.h file
#import <UIKit/UIKit.h>
#protocol MPPopoverControllerDelegate;
#interface MPPopoverController : UIViewController <MPPopoverControllerDelegate>
#property (nonatomic, assign) id<MPPopoverControllerDelegate> delegate;
#end
MPPopoverController.m file
#import "MPPopoverController.h"
#import "MPPopoverControllerDelegate.h"
#implementation MPPopoverController
#end
#property (nonatomic, assign) id<MPPopoverControllerDelegate> delegate; : this line has warning
Cannot find protocol definition for 'MPPopoverControllerDelegate'
What is wrong? And how to fix this warning?
if replace '#protocol MPPopoverControllerDelegate'; with '#import "MPPopoverControllerDelegate.h', everything will be ok. But link - in Referring to Other Protocols you can see that apple says to use #protocol
Is there an absolute need for your protocol declaration to be in a different header file? Unless it's quite a large protocol definition (which yours isn't), I would suggest declaring it below your interface declaration.
MPPopoverController.h
#import <UIKit/UIKit.h>
#protocol MPPopoverControllerDelegate;
#interface MPPopoverController : UIViewController
#property (nonatomic, assign) id<MPPopoverControllerDelegate> delegate;
#end
#protocol MPPopoverControllerDelegate <NSObject>
#optional
- (void)popoverControllerDidDismissPopover:(MPPopoverController *)popoverController;
#end
Compiler read your .m file, and load .h files when necessary. So it loads MPPopoverController.h first and when it read it delegate protocol is still undeclared. You could easily fix this warning just by swapping include lines. To let compiler read delegate .h file first.
#import "MPPopoverControllerDelegate.h"
#import "MPPopoverController.h"
#implementation MPPopoverController
#end
Are you sure you're ever including MPPopoverControllerDelegate.h somewhere?
Import MPPopoverControllerDelegate.h in MPPopoverController.h and MPPopoverController.h should look like:
The code copy pasted from the question and edited was removed. The following code is copy pasted from xcode.
The MPPopoverControllerDelegate.h:
#class MPPopoverController;
#protocol MPPopoverControllerDelegate <NSObject>
#optional
- (void)popoverControllerDidDismissPopover:(MPPopoverController *)popoverController;
#end
The MPPopoverController.h
#protocol MPPopoverControllerDelegate;
#interface MPPopoverController : UIViewController{
id<MPPopoverControllerDelegate> delegate;
}
#property (nonatomic, assign) id<MPPopoverControllerDelegate> delegate;
#end
The MPPopoverController.m
#implementation MPPopoverController
#synthesize delegate;
//rest of view controller class.
The problem is that in your MPPopoverController interface you specify <MPPopoverControllerDelegate>. This means that the class implements this protocol! Is wrong because the class is the owner of the protocol. So your logic is wrong in some point.

cannot find protocol declaration custom protocol delegate iphone

Slowly but surely getting this delegation and protocol stuff on iphone but I cannot understand this error.
I have declared my protocol in my first viewcontroller.
In the second viewcontroller i try to add it at the top after i have imported it into the header file and it cannot find it. see my code below.
//SendSMS
#import <UIKit/UIKit.h>
#import "LoginPage.h"
#import "MessageOptions.h"
#protocol SMSProtocol <NSObject>
-(NSString *)postbackType;
#end
#interface SendSMS : UIViewController <UITextViewDelegate, UITextFieldDelegate> {
id<SMSProtocol> delegate;
MessageOptions *messageOptions;
LoginPage *loginPage;
IBOutlet UITextField *phonenumber;
IBOutlet UITextView *smsBody;
IBOutlet UIScrollView *scrollview;
}
#property (nonatomic, retain) id<SMSProtocol> delegate;
-(IBAction)LoadMessageOptions;
#end
Then my second view
#import <UIKit/UIKit.h>
#import "SendSMS.h"
#interface ScheduledSMS : UIViewController <SMSProtocol>{
}
-(IBAction)popBack;
#end
That is surely strange. Have you tried restarting Xcode? Xcode has a habit of not indexing symbols for me when I add new files.
You should also look into how your naming conventions. SendSMS is not really a good class name, more of a action method name. I would go for SendSMSViewController, since that is what it is.
By that it would follow that SMSProtocol should be named SendSMSViewControllerDelegate, since that is what it is.
Methods in a delegate protocol should contain the sender and one of the three words will, did, or should. If not at the very least it should name what it expects to return. -(NSString *)postbackType; should probably be -(NSString *)postbackTypeForSendSMSViewController:(SendSMSViewController*)controller;.

Objective C Properties

I tried searching for this issue, but can't seem to find out what I'm doing wrong.
Here is my controller header:
#import <UIKit/UIKit.h>
#interface BabyLearnViewController : UIViewController {
UIButton *btnImage;
MediaManager* myMediaManager;
}
#property (nonatomic, retain) IBOutlet UIButton *btnImage;
#property (retain) MediaManager* myMediaManager;
- (IBAction)setNewImage;
#end
Here is my controller class:
#import "BabyLearnViewController.h"
#import "MediaManager.h";
#implementation BabyLearnViewController
#synthesize btnImage;
#synthesize myMediaManager;
I am getting the errors:
error: expected specifier-qualifier-list before 'MediaManager'
error: no declaration of property 'myMediaManager' found in the interface
Any ideas? Usually the 1st error comes up if you have a cylical reference. 'MediaManager' doesn't reference anything else. Any ideas?
Since you have no mentions of MediaManager class at the moment it is used in header file compiler can't figure out what "MediaManager" is and issues an error. Declare that class using forward declaration in your header file to let compiler know that MediaManager is actually a class:
#class MediaManager;
#interface BabyLearnViewController : UIViewController {
...
P.S. As an alternative you can import MediaManager.h in your header, but using forward declaration is preferred.
Place #import "MediaManager.h"
this in header file of BabyLearnViewController
try add #class MediaManager; before #interface

Syntax for creating View delegate in Objective-C

I am trying to create a delegate protocol for a custom UIView. Here is my first attempt:
#protocol FunViewDelegate
#optional
- (void) funViewDidInitialize:(FunView *)funView;
#end
#interface FunView : UIView {
#private
}
#property(nonatomic, assign) id<FunViewDelegate> delegate;
#end
This doesn't work because the FunView interface has not been declared at the time of the FunViewDelegate declaration. I have tried adding a prototype ala C++ before the #protocol:
#interface FunView;
But this just drives the compiler nuts. How am I supposed to do this?
Forward class syntax is #class Foo;, not #interface Foo;.
It would seem that you can forward declare protocols:
#protocol FunViewDelegate;
#interface FunView : UIView {
#private
id<FunViewDelegate> delegate;
}
#property(nonatomic, assign) id<FunViewDelegate> delegate;
#end
#protocol FunViewDelegate
#optional
- (void) funViewDidInitialize:(FunView *)funView;
#end