A delegate can be any class that implements the required functions. Typically you'll make your viewController the delegate for something, but it can be anything.
You don't subclass UITextField for instance. You set another object as it's delegate and declare that object as implementing the UITextFieldDelegate.
In your header file:
@interface LoginViewController : UIViewController <UITextFieldDelegate> {
IBOutlet UITextField *userNameField;
IBOutlet UITextField *passwordField;
}
Then in your source file implement whatever methods of the UITextFieldDelegate that you are interested in and they will be called when those events are occur on the textField.
- (void)viewDidLoad
{
userNameField.delegate = self;
passwordField.delegate = self;
}
- (void)textFieldDidBeginEditingUITextField *)textField
{
[self setViewMovedUp:50];
}
编辑文本时,自动上滑
最新推荐文章于 2023-02-11 09:39:48 发布