iphone UIAlertView焦点问题

时间:2010-11-20 11:53:32

标签: iphone objective-c uialertview

我正在使用一个简单的警报来显示一条长消息,我按以下方式处理警报:


bool        hold_alert = true;
UIAlertView * malert = [[UIAlertView alloc]....create the alert
[malert show];
while(hold_alert)
{//hold the application focus on the alert, when alert triggers the function with "clickedButtonAtIndex" i set hold_alert to false
    CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.05,false);
}
[malert removeFromSuperView];
[my_window becomeFirstResponder];
... release alert and stuff , and carry on...

问题是此代码不会将焦点放在我的应用程序上。有趣的是,当我使用breakepoints在调试器中运行这段代码时,控件成功恢复到我的应用程序。 我该如何解决这个问题?

谢谢, Raxvan。

1 个答案:

答案 0 :(得分:1)

有点不清楚你想用runloop函数实现什么......

但也许

-(void)presentAlert
{
UIAlertView * malert = UIAlertView *aview = [[[UIAlertView alloc] initWithTitle:@"Blah" message:@"blah blah" cancelButtonTitle:@"OK" delegate:self otherButtonTitles:nil] autorelease];                                                                                                                                                                                                       
[malert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex) { foo }
}

你想要什么,因为在记忆和观点方面,你的其余部分都是为你完成的。没有必要明确关注警报。

如果在警报启动时您想要做某事,您可以按照原样启动重复计时器。

    -(void)presentAlert
    {
    UIAlertView * malert = UIAlertView *aview = [[[UIAlertView alloc] initWithTitle:@"Blah" message:@"blah blah" cancelButtonTitle:@"OK" delegate:self otherButtonTitles:nil] autorelease];                                                                                                                                                                                                       
    [malert show];
    iTimer = [[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(doStuff:) userInfo:nil repeats:YES] retain];

    }

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    [iTimer invalidate];
    [iTimer release];   
    if (buttonIndex) { //foo }
    }

    -(void)doStuff:(NSTimer *)aTimer
   {
       //bar
   }