1> 遵守UITextFieldDelegate協議
2> UITextFieldDelegate協議的內容
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; //編輯框能否開始編輯時調用(基本不用)
- (void)textFieldDidBeginEditing:(UITextField *)textField; //編輯框已經開始編輯時調用,編輯框成為FirstResponder
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField; //編輯框停止編輯時調用(基本 不用)
- (void)textFieldDidEndEditing:(UITextField *)textField; //編輯結束時調用(一般用于收回鍵盤或者檢測上一個編輯框是否為空,例如登錄界面等)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; //輸入文字時執行該方法
- (BOOL)textFieldShouldClear:(UITextField *)textField; //確定清除按鍵是否可用,一般設置為YES,也可用設置在特定的情況下才允許用戶清空
- (BOOL)textFieldShouldReturn:(UITextField *)textField; //當按下return鍵是調用,例如搜索等,如果允許調用resignFirstResponder方法,這將會導致編輯結束,鍵盤將會被收起