ios - 创建委托(delegate)时收到警告
<p><p>我正在使用 <a href="https://github.com/gaurvw/MPGTextField" rel="noreferrer noopener nofollow">MPGTextField</a> .在 <code>.h</code> 文件中,我收到以下警告:</p>
<blockquote>
<p>Auto property synthesis will not synthesize property 'delegate', it
will be implemented by its superclass, use @dynamic to acknowledge
intention</p>
</blockquote>
<p>代码如下:</p>
<pre><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;
</code></pre>
<p>出了什么问题,我该如何解决?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是因为您的 <code>MPGTextField</code> 继承自 <code>UITextField</code> 已经具有名为 <code>delegate</code> 的属性。<br/>
要修复警告,只需在实现文件中写入以下内容:<br/>
//MPGTextField.m</p>
<pre><code>@dynamic delegate;
@implementation MPGTextField
//...
@end
</code></pre>
<p>或者创建一个新属性并使用它,如下所示:<br/>
<code>@property (nonatomic, weak) id <MPGTextFieldDelegate, UITextFieldDelegate> myDelegate;</code></p>
<pre><code>@implementation MPGTextField
//...
- (void)setMyDelegate:(id <MPGTextFieldDelegate, UITextFieldDelegate>)myDelegate
{
_myDelegate = myDelegate;
self.delegate = myDelegate;
}
@end
</code></pre></p>
<p style="font-size: 20px;">关于ios - 创建委托(delegate)时收到警告,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31082924/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31082924/
</a>
</p>
页:
[1]