UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Please check your internet connection"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
You are setting the delegate to self
, but you aren't defining the UIAlertView protocol in your ReservierungsformularBHV.h
Change
@interface ReservierungsformularBHV : UIViewController
to
@interface ReservierungsformularBHV : UIViewController <UIAlertViewDelegate>
and in your ReservierungsformularBHV.m add the following:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog("Dismissing alert");
}
Here's the link to the apple docs on UIAlertView: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html
EDIT: in your .h file change
@interface ReservierungsformularBHV : UIViewController
to
@interface ReservierungsformularBHV : UIViewController <UIAlertViewDelegate, UIWebViewDelegate>
and change your viewDidLoad
function to the following:
- (void)viewDidLoad {
webview.delegate=self;
NSURL *url = [NSURL URLWithString:@"http://www.bodega-online.com/tischreservierung /mail_formular.php?ort=Bremerhaven"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webview loadRequest:req];
[super viewDidLoad];
}
Let me explain what this does:
A webview has some so-called delegate functions, which are getting called in different cases. Your webViewDidFail
-function was never called, because your webview didn't have the correct delegate assigned, which is done by defining the UIWebViewDelegate protocol in your .h file and setting the proper delegate in viewDidLoad
to self
. You could also have some other class handle your webview, but in this case you can use it like explained above.
Anyway, you should use the Reachability framework for checking on active internet connection and show the Alert if the device is not connected. There are a couple of examples how to do this on the web.