2012-12-13 18 views
0

当我显示在textFieldDidBeginEditing动作片隐藏键盘,这里是我的代码:问题用行动表

- (void)textFieldDidBeginEditing:(UITextField *)textField { 
    // dept_label is my UITextField property 
    if (textField == dept_label) { 
     [textField setUserInteractionEnabled:YES]; // i also used dept_label instead textfield here... 
     [textField resignFirstResponder]; 
     UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select" 
                   delegate:self 
                 cancelButtonTitle:@"OK" 
                destructiveButtonTitle:nil 
                 otherButtonTitles:@"Manpower", @"Admin",@"Research" ,nil]; 
     [actionSheet setActionSheetStyle:UIActionSheetStyleDefault]; 
     [actionSheet showInView:self.view]; 
    } 
} 

问题是动作片得到激活,但键盘是没有得到隐藏!

+0

放'睡眠(0.5);'语句之后'[文本字段resignFirstResponder];':P –

+0

我不认为它的时间问题,因为即使选择后操作手册中的值,键盘仍然是隐藏的! – BaSha

+0

你试过了吗?它无论如何。如果键盘以前没有隐藏。选择UIActionSheet按钮后,您不希望键盘被隐藏。 –

回答

0
finally this worked.. 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
    if(textField==dept_label){   
     [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;  
} 
0

使用UITextField委托这样的:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    if (textField == dept_label) { 
     // dept_label is my UITextField property 
     [textField setUserInteractionEnabled:YES]; 
     UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select" 
                   delegate:self 
                 cancelButtonTitle:@"OK" 
                destructiveButtonTitle:nil 
                 otherButtonTitles:@"Manpower", @"Admin", @"Research", nil]; 
     [actionSheet setActionSheetStyle:UIActionSheetStyleDefault]; 
     [actionSheet showInView:self.view]; 
     return NO; 
    } 
    return YES; 
} 
+0

thnks omk,我试过这个,但它限制键盘显示从我所有的文本字段,因为我们返回NO,所以我稍微修改了你的代码,现在它的工作:) – BaSha