2012-12-13 15 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