问题描述
我在 uiactionsheet 中添加了 textfeld 作为
-(void)showAction {printf("准备行动\n");UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"New Sheet Name" delegate:self cancelButtonTitle:@"Cancel" corruptionButtonTitle: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 成为FirstResponder];[textField setKeyboardType:UIKeyboardTypeAlphabet];[textField setKeyboardAppearance:UIKeyboardAppearanceAlert];textField.text="test" ;textField.delegate=self;[asheet insertSubview:textField atIndex:0];[textField 发布];[单张发布];}但键盘不适用于此文本字段,但退格键有效.以前,当我使用 ios 3 时,它工作正常,但使用 ios 3.2 iphone 模拟器 4.0 不接受来自键盘的任何输入
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{printf("\n textFieldShouldBeginEditing\n ");返回是;}
这被称为
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{printf("shouldChangeCharactersInRange %s",[string UTF8String]);返回是;}
但是,此委托方法仅在退格时调用.
就用这种方式对我有用
首先在你的类 .h 文件中设置 UITextFieldDelegate,UIActionSheetDelegate
#define TEXT_FIELD_TAG 9999
#define ACTION_SHEET_TAG 8888
-(IBAction)ForgotPassword:(id)sender{UIActionsheet *actFollowUp = [[UIActionSheet alloc] initWithTitle:@"请输入邮箱"委托:自己取消按钮标题:@"取消"破坏性按钮标题:@"好的"otherButtonTitles:nil];actFollowUp.tag=ACTION_SHEET_TAG;textFieldTime = [[UITextField alloc] initWithFrame:CGRectMake(60.f,320.f, 200.f, 30.f)];[textFieldTime setBackgroundColor:[UIColor whiteColor]];textFieldTime.delegate= self;[textFieldTime setKeyboardType:UIKeyboardTypeAlphabet];textFieldTime.keyboardAppearance= UIKeyboardAppearanceAlert;textFieldTime.tag=TEXT_FIELD_TAG;[actFollowUp addSubview:textFieldTime];UIWindow* appWindow = [UIApplication sharedApplication].keyWindow;[actFollowUp showInView:appWindow];[actFollowUp setFrame:CGRectMake(0.0,200.0, 320.0, 200.0)];[self performSelector: @selector(acceptInput:) withObject: actFollowUp];
}
-(void)acceptInput: (UIActionSheet*)actionSheet{UITextField* textField = (UITextField*)[actionSheet viewWithTag:TEXT_FIELD_TAG];UIWindow* appWindow = [UIApplication sharedApplication].keyWindow;CGRect 框架 = textField.frame;[appWindow insertSubview:textField aboveSubview:actionSheet];frame.origin.y += 60.0;//将文本字段移动到与操作表上相同的位置textField.frame = 框架;}
i have added textfeld in uiactionsheet as
-(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];
}
but keypad is not working for this textfield however backspace is working.previously when i have been using ios 3 its workd fine but with ios 3.2 iphone simulator 4.0 does not accept any input from keypad
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
printf("\n textFieldShouldBeginEditing\n ");
return YES;
}
this gets called
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
printf("shouldChangeCharactersInRange %s ",[string UTF8String]);
return YES;
}
however this delegate method gets called only for backspace.
Just use this way it works for me
First set the the UITextFieldDelegate,UIActionSheetDelegate in your class .h file
#define TEXT_FIELD_TAG 9999
#define ACTION_SHEET_TAG 8888
-(IBAction)ForgotPassword:(id)sender{
UIActionsheet *actFollowUp = [[UIActionSheet alloc] initWithTitle:@"Please Enter Email"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"OK"
otherButtonTitles:nil];
actFollowUp.tag=ACTION_SHEET_TAG;
textFieldTime = [[UITextField alloc] initWithFrame:CGRectMake(60.f,320.f, 200.f, 30.f)];
[textFieldTime setBackgroundColor:[UIColor whiteColor]];
textFieldTime.delegate= self;
[textFieldTime setKeyboardType:UIKeyboardTypeAlphabet];
textFieldTime.keyboardAppearance= UIKeyboardAppearanceAlert;
textFieldTime.tag=TEXT_FIELD_TAG;
[actFollowUp addSubview:textFieldTime];
UIWindow* appWindow = [UIApplication sharedApplication].keyWindow;
[actFollowUp showInView:appWindow];
[actFollowUp setFrame:CGRectMake(0.0,200.0, 320.0, 200.0)];
[self performSelector: @selector(acceptInput:) withObject: actFollowUp];
}
-(void)acceptInput: (UIActionSheet*)actionSheet
{
UITextField* textField = (UITextField*)[actionSheet viewWithTag:TEXT_FIELD_TAG];
UIWindow* appWindow = [UIApplication sharedApplication].keyWindow;
CGRect frame = textField.frame;
[appWindow insertSubview:textField aboveSubview:actionSheet];
frame.origin.y += 60.0; // move text field to same position as on action sheet
textField.frame = frame;
}
这篇关于键盘不适用于 uiactionsheet 中的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!