我正在使用MPGTextField。在.h
文件中,我收到以下警告:
自动属性合成不会合成属性'委托',它 将由其超类实现,使用@dynamic来确认 意图
以下是代码:
#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;
有什么问题,我该如何解决?
答案 0 :(得分:2)
这是因为您的MPGTextField
继承自UITextField
已经拥有名为delegate
的媒体资源。
要修复警告,只需在实现文件中写下以下内容:
//MPGTextField.m
@dynamic delegate;
@implementation MPGTextField
//...
@end
或者制作一个新属性并使用它,如下所示:
@property (nonatomic, weak) id <MPGTextFieldDelegate, UITextFieldDelegate> myDelegate;
@implementation MPGTextField
//...
- (void)setMyDelegate:(id <MPGTextFieldDelegate, UITextFieldDelegate>)myDelegate
{
_myDelegate = myDelegate;
self.delegate = myDelegate;
}
@end
答案 1 :(得分:0)
我还有一个StepRecipeViewController(UIViewController)。我想将信息从StepRecipeContainerPageViewController传递给StepRecipeViewController。
这是我的解决方案。
StepRecipeContainerPageViewController类:
@protocol StepRecipeContainerPageViewControllerDelegate<NSObject>
-(void) passInformation :(NSString*)someInfo;
@end
@interface StepRecipeContainerPageViewController : UIPageViewController<StepRecipeContainerPageViewControllerDelegate, UIPageViewControllerDelegate, UIPageViewControllerDataSource>{}
@property (assign, nonatomic) id <UIPageViewControllerDelegate, StepRecipeContainerPageViewControllerDelegate> myDelegate;
我在这个类中调用了这个函数:
[self.myDelegate passInformation:@"works"];
StepRecipeViewController类:
#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);
}