views:

26

answers:

1

hello all i m try to use a delegate method in my simple iphone application but i got a error. if there are any example code. pls send me link or code.

A: 

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;
jtbandes