.h
IBOutlet UIWebView *webview;
.m
- (void)viewDidLoad {
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://blabla.com"]]];
}
- (void)webView:(UIWebView *)webViewfail didFailLoadWithError:(NSError *)error {
if([webViewfail isEqual:webview]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed"
message:@"Check your Internet connection before refreshing."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
I do not know what I did wrong, I tried making it appear but setting off internet connection. Any tips or suggestions will be helpful.
Make sure you have hooked up the delegate in interface builder (if that is what you are using). You can do this by selecting the web view, and drag (while holding control) to the view controller / file’s owner, and then select delegate (which pops up when you release the mouse).
Or you can hook up your delegate in code in your viewDidLoad method like so:
Make sure your view controller conforms to the UIWebViewDelegate protocol by adding in your .h
Good luck 🙂