//點擊後取消所有的編輯狀態
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//可以直接寫在UIViewController當中
{
[self.view endEditing:YES];
}
//利用textField的delegate
Implement UITextFieldDelegate:
@interface yourClass : UIViewController
Use the delegate method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//do whatever you need here
//maybe you have several textFields, so first check which one was hit the return key:
if(textField == outlet_to_your_textField_1){
//do this
}
else if(textField == outlet_to_your_textField_2){
//do that
}
else if .... blablabla and so on
return YES;
}
沒有留言:
張貼留言