2011-11-18 58 views
3

我有一个警告视图,并将uitextfield添加为子视图。iPhone AlertView文本字段键盘不可见

在我的uitableview控制器中,键盘显示正常。

http://i301.photobucket.com/albums/nn76/hackmodford/c804bd91.jpg

然而,在不同的视图我想要做同样的事情。因此,我没有使用UITableView控制器,而是将它制作为UIViewController,以便我可以在视图的底部添加一个工具栏。

但是,当我显示UIAlertView键盘被隐藏。我认为这是在视图背后,因为警报视图向上移动,为键盘腾出空间。

http://i301.photobucket.com/albums/nn76/hackmodford/5680aaa2.jpg

任何想法?

UPDATE:

键盘是被隐藏是因为我出了警报后解雇一个modalviewcontroller的原因。出于某种原因,它也会解雇我的键盘。刚刚重新安排一个合适的工作现在罚款...的顺序

回答

5

尝试实施didPresentAlertView:方法中的文本字段设置为firstResponder像这样:

- (IBAction)someActionThatTriggersAnAlertView:(id)sender { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TITLE" message:@"MESSAGE" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil]; 
    alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    UITextField *someTextField = [alert textFieldAtIndex:0]; 
    someTextField.keyboardType = UIKeyboardTypeAlphabet; 
    someTextField.keyboardAppearance = UIKeyboardAppearanceAlert; 
    someTextField.autocorrectionType = UITextAutocorrectionTypeNo; 
    [alert show]; 
    [alert release]; 
} 

#pragma mark - UIAlertViewDelegate Methods 

- (void)didPresentAlertView:(UIAlertView *)alertView { 
    [[alertView textFieldAtIndex:0] becomeFirstResponder]; 
} 

UIAlertView Documentation
UIAlertViewDelegate Documentation

+0

,完美的工作!甚至比延迟更好...谢谢 – Hackmodford

+0

没问题,乐意帮忙=) – chown

相关问题