OGeek|极客世界-中国程序员成长平台

标题: ios - 创建委托(delegate)时收到警告 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:40
标题: ios - 创建委托(delegate)时收到警告

我正在使用 MPGTextField .在 .h 文件中,我收到以下警告:

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

代码如下:

#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;

出了什么问题,我该如何解决?



Best Answer-推荐答案


这是因为您的 MPGTextField 继承自 UITextField 已经具有名为 delegate 的属性。
要修复警告,只需在实现文件中写入以下内容:
//MPGTextField.m

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

或者创建一个新属性并使用它,如下所示:
@property (nonatomic, weak) id myDelegate;

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

关于ios - 创建委托(delegate)时收到警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31082924/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4