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。

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!