I have this set of code which was working fine about an hour or so ago. Then when I tried to launch it again few min back, the UIWebView just display a white screen. But if now I blocked out the -(bool) method, the viewDidLoad will occur. (tested with the NSLog) May I ask what happened to the code?? It was working and suddenly it stop functioning.
.m
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSString *titleString = @"Error Loading Page";
NSString *messageString = [error localizedDescription];
NSString *moreString = [error localizedFailureReason] ?
[error localizedFailureReason] :
NSLocalizedString(@"Try typing the URL again.", nil);
messageString = [NSString stringWithFormat:@"%@. %@", messageString, moreString];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:titleString
message:messageString delegate:self
cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alertView show];
}
if i implement the above method, the app when open UIWebView will constant pop up saying error domain error -999 non stop.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *currentURL = [[request URL] absoluteString];
NSRange range1= [currentURL rangeOfString:@"news"];
NSRange range2= [currentURL rangeOfString:@"pdf"];
if (range1.location == NSNotFound)
{
NSURL *url = [NSURL URLWithString:@"http://www.imc.jhmi.edu/news.html"];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
return YES;
}
if(range2.location==NSNotFound)
{
NSURL * url = [NSURL URLWithString:@"http://www.imc.jhmi.edu/news.html"];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
return YES;
}
return NO;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
webView.scalesPageToFit=YES;
webView.delegate = self;
NSString *urlAddress = @"http://www.imc.jhmi.edu/news.html";
NSURL *url =[NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
NSLog(@"sadfasdf");
}
.h @interface ViewController : UIViewController{ IBOutlet UIWebView*webView; }
@property(nonatomic,strong) UIWebView*webView;
@end