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。

    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突