Search code examples
iphoneios4uiactionsheet

Issue with Hiding keyBoard when using Action sheet


I'm showing action sheet on textFieldDidBeginEditing, here is my code:

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

Problem is the action sheet is get activated but keyboard is not getting hidden!


Solution

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