iphone - 可达性中的 UIAlertView 异常

标签 iphone ios ios5 uialertview reachability

我是 iOS 的新手,我在以编程方式关闭 UIAlertView 时遇到了问题。

我在 .h 文件中声明了警报:

@interface ViewController : UIViewController<UIWebViewDelegate>{
    UIWebView *webView;
    UIAlertView *alert;
}

@property(nonatomic, retain) IBOutlet UIWebView *webView;
@property(nonatomic, retain) IBOutlet UIAlertView *alert;

在 .m 文件中,我使用此警报来警告用户有关互联网连接的信息:

@synthesize alert;
-(void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
    case NotReachable:
    {
        NSLog(@"The internet is down.");
        self.internetActive = NO;
        alert = [[[UIAlertView alloc] initWithTitle:@"Network Unavailable" 
                                                         message:@"Internet connectivity could not be established!" 
                                                        delegate:self 
                                               cancelButtonTitle:nil 
                                               otherButtonTitles:nil] autorelease];
        [alert show];
        break;
    }
    default:
    {
        [alert dismissWithClickedButtonIndex:0 animated:NO];

    }
}

现在,当互联网连接中断时,会出现警报。但是,当建立互联网连接时,程序会抛出异常,提示无法访问该对象。谁能告诉我我做错了什么?

最佳答案

1- 在头文件中实现 UIAlertViewDelegate

2-使用这个方法

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

}

在此方法中,根据点击按钮的索引消除警报 View

关于iphone - 可达性中的 UIAlertView 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11542857/

相关文章:

ios - 如何在 Objective-c ios 中抑制 PMD 重复?

ios5 - NSArray 导致 viewDidLoad 崩溃

ios - 如何为 iPad 保持相同样式的 `portrait` 到 `landscape`

ios - 在非基于文档的应用程序中保存数据

objective-c - 你能通过 dismissModalViewControllerAnimated : or do you need a segue for the return journey? 返回数据吗

ios - 如何检查用户是否在 Twitter 上关注您?

iphone - 如何从 SQLite 中正确读取和打印重音字符?

ios - AdMob iOS,在测试设备上展示广告

ios - Iphone 6 plus 模拟器工作正常,除了设备

ios - Cocos2d 游戏在某些设备上无法启动