Jessica
Jessica

Reputation: 9830

I get warning when creating delegate

I'm using MPGTextField. At the .h file, I get the following warning:

Auto property synthesis will not synthesize property 'delegate', it will be implemented by its superclass, use @dynamic to acknowledge intention

Here is the code:

#import <UIKit/UIKit.h>

@protocol MPGTextFieldDelegate;

@interface MPGTextField : UITextField <UITableViewDelegate, UITableViewDataSource, UIPopoverControllerDelegate, UITextFieldDelegate, UIGestureRecognizerDelegate>

// Here is where I get the warning:
@property (nonatomic, weak) id <MPGTextFieldDelegate, UITextFieldDelegate> delegate;

What is wrong, and how can I do to fix it?

Upvotes: 2

Views: 787

Answers (2)

delarcomarta
delarcomarta

Reputation: 273

Also I have a StepRecipeViewController (UIViewController). I want to pass information from StepRecipeContainerPageViewController to StepRecipeViewController.

This has been my solution.

The StepRecipeContainerPageViewController class:

@protocol StepRecipeContainerPageViewControllerDelegate<NSObject>
-(void) passInformation :(NSString*)someInfo;
@end

@interface StepRecipeContainerPageViewController : UIPageViewController<StepRecipeContainerPageViewControllerDelegate, UIPageViewControllerDelegate, UIPageViewControllerDataSource>{}

@property (assign, nonatomic) id <UIPageViewControllerDelegate, StepRecipeContainerPageViewControllerDelegate> myDelegate;

I call this function in this class:

[self.myDelegate passInformation:@"works"];

The StepRecipeViewController class:

#import "StepRecipeContainerPageViewController.h"    
@interface StepRecipeViewController : UIViewController<StepRecipeContainerPageViewControllerDelegate, UIPageViewControllerDelegate>{}

@implementation StepRecipeViewController

- (void)viewDidLoad {
[super viewDidLoad];

StepRecipeContainerPageViewController *vc = [[StepRecipeContainerPageViewController alloc]initWithNibName:@"StepRecipeContainerPageViewController" bundle:nil];
    [vc setMyDelegate:self];
    [self.navigationController pushViewController:vc animated:YES];
    }

-(void) passInformation :(NSString*)someInfo{
        NSLog(@"Other class %@",someInfo);
}

Upvotes: 0

arturdev
arturdev

Reputation: 11039

Its because your MPGTextField inherits from UITextField which already has property named delegate.
To fix the warning just write following in the implementation file:
//MPGTextField.m

@dynamic delegate;  
@implementation MPGTextField
//...
@end

Or make a new property and use that one, something like this:
@property (nonatomic, weak) id <MPGTextFieldDelegate, UITextFieldDelegate> myDelegate;

@implementation MPGTextField
//...
- (void)setMyDelegate:(id <MPGTextFieldDelegate, UITextFieldDelegate>)myDelegate 
{
    _myDelegate = myDelegate;
    self.delegate = myDelegate;
}
@end

Upvotes: 2

Related Questions