1

我在基于消息传递的 iPhone 应用程序中工作。在我的一个 UIViewController 中,我正在显示 UITextView 键盘并从 web 服务中收到一些警报消息。

当我在 UIAlertView 中显示警报消息时,通过单击 UIAlertView 中的确定按钮来关闭 UITextview 键盘。我试图将 becomeFirstResponder 放在 UIAlertView 委托中,但仍然键盘关闭。供你参考,

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   [messageTextView becomeFirstResponder]; // Here again I am giving becomeFirstResponder to my UITextView

   int alertMessageArrayCount = [alertMessageArray count];
    if (messageAlertView) 
    {
        if (messageAlertCount < alertMessageArrayCount)  // These codes to show my all messages in UIAlertView one by one..
        {
            messageAlertCount = messageAlertCount + 1;

            arrayObjectValue = arrayObjectValue + 1;

            NSString *alertMessage = [alertMessageArray objectAtIndex:arrayObjectValue];

            messageAlertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:alertMessage delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [messageAlertView show];
            [messageAlertView release];
        }
    }
}

有人可以帮忙解决这个问题吗?

编辑 :

messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
messageTextView.delegate = self;
messageTextView.backgroundColor = [UIColor clearColor];
messageTextView.clipsToBounds = NO;
messageTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
[self.view addSubView:messageTextView];
4

2 回答 2

1

在您的 UIAlertView 委托方法中尝试如下所示的 [messageTextView becomeFirstResponder];

if([messageTextView resignFirstResponder]){
    [messageTextView becomeFirstResponder];
    }
于 2012-10-01T13:11:29.630 回答
0

写 alertview 的委托“nil”而不是 self。

 messageAlertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:alertMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
于 2012-10-01T10:51:18.673 回答