Warning about assigning to id<UITextFieldDelegate> when I'm conforming to the protocol

允我心安 提交于 2019-12-08 16:27:14

问题


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:

"Assigning to 'id' from incompatible type 'AddReviewViewController *const __strong'"

My header file is this:

#import <UIKit/UIKit.h>

@interface AddReviewViewController : UIViewController <UITextFieldDelegate>
@property (nonatomic) int storeID;

@end

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;

in the section "@interface AddReviewViewController ()"

Then, in viewDidLoad I do:

_reviewTextView.delegate = self;

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....

EDIT: 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!


回答1:


In your header you have UITextFieldDelegate And then you declare UITextView. There's a big difference between those two.

Edit

@interface AddReviewViewController : UIViewController <UITextFieldDelegate>

to

@interface AddReviewViewController : UIViewController <UITextViewDelegate>



回答2:


Maybe It should be UITextViewDelegate in :

@interface AddReviewViewController : UIViewController <UITextFieldDelegate>
@property (nonatomic) int storeID;
@end



回答3:


I was getting such error because of this code:

@interface PlaceOrderController : UIViewController <     UINavigationControllerDelegate, UITextViewDelegate >

@property (weak, nonatomic) IBOutlet UITextField *dateForUserDOB;

To solve this I have used following:

@interface PlaceOrderController : UIViewController < UINavigationControllerDelegate, UITextFieldDelegate >

@property (weak, nonatomic) IBOutlet UITextField *dateForUserDOB;

Summary : use TextField not TextView



来源:https://stackoverflow.com/questions/21086721/warning-about-assigning-to-iduitextfielddelegate-when-im-conforming-to-the-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!