问题描述
我的视图控制器符合 UITextFieldDelegate,但是当我尝试将文本字段的 .delegate 字段设置为 self 时,我收到警告:
My view controller is conforming to UITextFieldDelegate, yet when I try and set the .delegate field of my text field to self, I get the warning:
从不兼容的类型‘AddReviewViewController *const __strong’分配给‘id’"
我的头文件是这样的:
#import <UIKit/UIKit.h>
@interface AddReviewViewController : UIViewController <UITextFieldDelegate>
@property (nonatomic) int storeID;
@end
如您所见,我已声明它符合协议.在 .m 文件中,我有这个:
So as you can see, I have it declared to conform to the protocol. In the .m file, I have this:
@property (strong, nonatomic) IBOutlet UITextView *reviewTextView;
在@interface AddReviewViewController()"部分
in the section "@interface AddReviewViewController ()"
然后,在 viewDidLoad 中:
Then, in viewDidLoad I do:
_reviewTextView.delegate = self;
这就是我收到警告的地方.我试过清理和重建,并重新启动 XCode.我在这里遗漏了一些明显的东西吗?我遵守协议....
That's where I get the warning. I've tried cleaning and rebuilding, and restarting XCode. Am I missing something obvious here? I'm conforming to the protocol....
感谢您的快速帮助.在我睡眠不足的状态下,我不断地重新阅读东西并发誓这就是我正在做的事情,但是是的,打错了.几分钟内我无法标记答案,但问题已解决,谢谢!
Thanks for the quick help. In my sleep deprived state I kept re-reading things and swore that's what I was doing but yup, typo. I can't mark an answer for a few minutes, but problem solved, thanks!
推荐答案
在你的标题中有 UITextFieldDelegate
然后你声明UITextView
.这两者有很大的不同.
In your header you have UITextFieldDelegate
And then you declare UITextView
. There's a big difference between those two.
编辑
@interface AddReviewViewController : UIViewController <UITextFieldDelegate>
到
@interface AddReviewViewController : UIViewController <UITextViewDelegate>
这篇关于关于分配给 id<UITextFieldDelegate> 的警告当我遵守协议时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!