// 首先, 在接口裡邊聲明要使用誰得Delegate, 這裡以textField為例 @interface delegateSampleViewController : UIViewController <UITextFieldDelegate> {} @end // 然後在實現文件中初始化得時候, 設置Delegate為self(自己) @implementation delegateSampleViewContro ller // .... UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 300, 400)]; textField.delegate = self; [textField becomeFirstResponder]; [cell.contentView addSubview:textField]; [textField release]; // .... } // 最後就可以在Delegate方法裡邊實現自己想要得效果 #pragma mark UITextFieldDelegate Method // called when 'return' key pressed. return NO to ignore. - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }
取消键盘
最新推荐文章于 2013-05-29 18:33:47 发布