开发者

Assigning ViewController to a delegate, Is it good?

开发者 https://www.devze.com 2023-04-13 08:13 出处:网络
I am newbie in iOS programming, Recently I came across a tutorial where author assigned a ViewController to a textField delegate. Is it good to do this? As Xcode is giving me warning.

I am newbie in iOS programming, Recently I came across a tutorial where author assigned a ViewController to a textField delegate. Is it good to do this? As Xcode is giving me warning.

discussIDTextField.delegate = self;

self is DiscussViewController and above code is inside DiscussViewController.m

Code works fine开发者_如何学Go but I don't like yellow bubbles showing on my screen while writing codes. If I want to get rid of this warning what should I do?

Warning : Assigning id from incompatible type 'DiscussViewController'.


The view controller (self) has to implement the UITextFieldDelegate protocol. So your @interface definition should look something like this:

@interface DiscussViewController : UIViewController <UITextViewDelegate>

And then of course in the implementation implement some of the delegated protocol methods.


In your .h file add UITextFieldDelegate between < > so that your view controller becomes text field delegate and then in the .m file implement delegate methods that you need.

@interface DiscussViewController : UIViewController <UITextFieldDelegate>
0

精彩评论

暂无评论...
验证码 换一张
取 消