lianlianbushell 2012-11-23 02:06 采纳率: 0%
浏览 2491

求助:如何禁用Alertview弹出

我的应用里面有一个Alertview,没有网络连接的时候会弹出来。但是我希望有网络连接的时候它可以自动禁用。代码如下:

-(void)reachabilityChanged:(NSNotification*)note

    {
        Reachability * reach = [note object];

        if([reach isReachable])
        {
            notificationLabel.text = @"Notification Says Reachable";
            NSLog(@"Internet is Up");



        }
        else
        {
            notificationLabel.text = @"Notification Says Unreachable";
            NSLog(@"Internet is Down");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please connect to Internet"
                                                            message:nil
                                                           delegate:self
                                                  cancelButtonTitle:nil
                                                  otherButtonTitles:nil];
            UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
            progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
            [alert addSubview:progress];
            [progress startAnimating];
            [alert show];
        }
    }
  • 写回答

1条回答

  • love_loveec 2012-11-23 02:57
    关注

    可以把alertView当做实体变量,然后在ivar调用didDismissWithButtonIndex,然后就可以在viewDidLoad中分配alert,然后:

     -(void)reachabilityChanged:(NSNotification*)note{
            Reachability * reach = [note object];
            if([reach isReachable])
            {
                notificationLabel.text = @"Notification Says Reachable";
                NSLog(@"Internet is Up");
                [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:0];
            }
            else
            {
                notificationLabel.text = @"Notification Says Unreachable";
                NSLog(@"Internet is Down");
    
                UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
                progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
                [alert addSubview:progress];
                [progress startAnimating];
                [alert show];
            }
        }
    
        -(void)dismissAlert:(UIAlertView *)alertView{
                  [alertView dismissWithClickedButtonIndex:0 animated:YES];
        }
    

    在头文件里执行UIAlertViewDelegate。

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料