我在 uiactionsheet 中添加了 textfeld 作为
-(void)showAction {
printf("getting action ready \n");
UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"New Sheet Name" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: nil];
[asheet showInView:self.view];
[asheet setFrame:CGRectMake(0, 70, 320,200)];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100,200, 25)];
textField.borderStyle= UITextBorderStyleRoundedRect;
[textField becomeFirstResponder];
[textField setKeyboardType:UIKeyboardTypeAlphabet];
[textField setKeyboardAppearance:UIKeyboardAppearanceAlert];
textField.text=@"test" ;
textField.delegate=self;
[asheet insertSubview:textField atIndex:0];
[textField release];
[asheet release];
}
但键盘不适用于此文本字段,但退格键正在工作。以前当我一直在使用 ios 3 时,它工作正常,但使用 ios 3.2 iphone 模拟器 4.0 不接受来自键盘的任何输入
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
printf("\n textFieldShouldBeginEditing\n ");
return YES;
}
这被称为
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
printf("shouldChangeCharactersInRange %s ",[string UTF8String]);
return YES;
}
但是,此委托方法仅在退格时才被调用。