UIAlertView带有no按钮,怎么关闭

应用中有一个alertView,在服务器返回响应时使用。在应用向服务器发送数据之后,alertView会显示,但是应该怎么关闭呢?

摘抄的部分代码:

   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Canceling reservation" message:@"please wait" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
        [alert show];

        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

        // Adjust the indicator to place at the bottom of the dialog window.
        indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height-50);
        [indicator startAnimating];
        [alert addSubview:indicator];
  • (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

UIAlertView 会一直显示在你的屏幕上,除非你点击了Cancel按钮.
在你的代码中可以看到,在创建UIAlertView 时 cancelButtonTitle otherButtonTitles 都没有设置,这样在显示UIAlertView时就没有任何按钮,也就无法通过UIAlertView 的代理方法来处理关闭动作.

你想要实现的效果使用MBProgressHUD 这个组件来实现比较好.