I’m new to iOS and I have a problem in dismissing an UIAlertView programmatically.
I declared the alert in .h file:
@interface ViewController : UIViewController<UIWebViewDelegate>{
UIWebView *webView;
UIAlertView *alert;
}
@property(nonatomic, retain) IBOutlet UIWebView *webView;
@property(nonatomic, retain) IBOutlet UIAlertView *alert;
and in the .m file I use this alert to warn the user about internet connectivity:
@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];
}
}
}
Now, when the internet connection is down the alert appears. However, when the internet connection get established the program throws exception complaining about bad access to the object. Can anybody tell me what am I doing wrong?
1- Implement the UIAlertViewDelegate in your header file
2- use this method
inside this method dismiss the alert view based on the index of clicked button