使用Action表时隐藏keyBoard的问题

时间:2012-12-13 13:54:48

标签: iphone ios4 uiactionsheet

我正在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];
    }
}

问题是操作表被激活但键盘没有被隐藏!

2 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分: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;      
}