我有四个Uitextfields,在一个文本字段中我设置了操作表和三个ohthers只是用于文本输入。这是我的代码..
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if(textField.tag==3)// tag will be integer
{
NSLog(@"ACTION SHEET WILL DISPLAY");
[textField setUserInteractionEnabled:YES];
[textField resignFirstResponder];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:@"Manpower", @"Admin",@"Research" ,nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField*)textField {
if (textField.tag) {
UIResponder *nextField = [textField viewWithTag:(textField.tag + 1)];
[nextField becomeFirstResponder];
}
else {
// Unknown field, just resign first responder.
[textField resignFirstResponder];
}
return NO;
}
现在我的问题是当我从三个文本字段中的任何一个按下键盘TAB键时,我的操作表显示出来了!虽然如果我单独单击文本字段,它可以正常工作。
答案 0 :(得分:1)
你所做的只是给xib中的不同文本域提供不同的标签,然后比较文本字段名称只比较标签并为该文本字段返回NO,这样当动作表打开时,键盘不会弹出...
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if(textField.tag==your textfield tag)// tag will be integer
{
NSLog(@"ACTION SHEET WILL DISPLAY");
[textField setUserInteractionEnabled:YES];
[textField resignFirstResponder];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:@"Manpower", @"Admin",@"Research" ,nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
return NO;
}
else
{
return YES;
}
}
让我知道它的工作与否......
快乐编码...... !!!!!
答案 1 :(得分:1)
可能会帮助你
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if(textField == dept_label)
{
NSLog(@"ACTION SHEET WILL DISPLAY");
[textField setUserInteractionEnabled:YES];
[textField resignFirstResponder];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:@"Manpower", @"Admin",@"Research" ,nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
return NO;
}
else
{
return YES;
}
}