如何在输入委托方法时隐藏uialertview?

时间:2012-10-17 13:02:50

标签: objective-c ios xcode ios5 ios6

大家好我有一个名为manageui的方法,它显示一段时间的等待视图,当超时时显示UIAlertView,显示消息再次尝试 我的问题是我在调用UIAlertView之前无法隐藏manageui

这是我的代码:

    -(void)mangeui
{
    double Currenttime=0;
    double ptime=Currenttime+5000;
     NSLog(@"fire /n");

    do 
    {
        //add condition for found session
        if (Currenttime<ptime)
        {
            NSLog(@"inside if");
            [spinner setHidden:NO];
            [alert setHidden:YES];
        }
        else
        {

            alert = [[UIAlertView alloc] initWithTitle:@"Oops:(" 
                                                            message:@"No device found \n Make sure bluetooth is activated and the devices are within range." 
                                                           delegate:self 
                                                  cancelButtonTitle:@"Tap to retry"
                                                  otherButtonTitles:nil];

         [spinner setHidden:YES];
            [alert show];

        }

        Currenttime+=1;
    } while (Currenttime < ptime+1 &&[_matchmakingClient availableServerCount]==0);
}

alertview的代表是:

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    [alertView dismissWithClickedButtonIndex:1 animated:true];
    [spinner setHidden:NO];

    alertView.hidden=YES;
    [self mangeui];
}

2 个答案:

答案 0 :(得分:1)

试试这个:

[alertView dismissWithClickedButtonIndex:0 animated:YES];

答案 1 :(得分:0)

我觉得你不理解代表的概念

此处docs显示alertView:clickedButtonAtIndex:

  

调用此方法后,接收器将自动关闭。

是的,没有必要单独声明要关闭警报视图。只要按下alertview中的按钮并且alertview消失

,就会调用该方法