-1

我有四个 Uitextfields,在一个文本字段上我设置了操作表和三个仅用于文本输入的其他字段。这是我的代码..

   - (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 键时,会显示我的操作表!,但如果我单独单击文本字段,它工作得很好。

4

2 回答 2

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;
}

 }

让我知道它是否有效...

快乐编码...!!!!!!

于 2012-12-14T06:30:10.123 回答
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;
}       
}
于 2012-12-14T06:38:02.517 回答