我是 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];
}
}
}
现在,当互联网连接断开时,会出现警报。但是,当互联网连接建立时,程序会抛出异常,抱怨对对象的访问不正确。谁能告诉我我做错了什么?