开发者

How are delegate methods used [closed]

开发者 https://www.devze.com 2023-01-09 05:33 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more开发者_JAVA技巧 detail or include a minimal example in the question itself.

Closed 8 years ago.

Improve this question

I am trying to use a delegate method in my simple iPhone application but I got an error. If there are any examples code; pls send me a link or code.


When using delegates there are a few things to take care of.

For example, say you have a class MyController and you want it to be a UITextField's delegate. Put the delegate protocol name in the class's interface:

@interface MyController : NSObject <UITextFieldDelegate>

Then, implement the delegate methods in the UITextFieldDelegate docs (the docs say "All of the methods of this protocol are optional." so you can choose which you want):

@implementation MyController
...

- (BOOL)textFieldShouldReturn:(UITextField *)textField
    // do something
}

...
@end

Then finally, set yourself as the delegate:

myTextField.delegate = self;
0

精彩评论

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