@interface SecondViewController : UIViewController <UIWebViewDelegate> {
- (void) LoadMyWebView
{
// Get your UIWebView, for example:
UIWebView *myView = (UIWebView *)self.view;
myView.delegate = self; // To be sure...
[myView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.weston-fl.com/"]];
}
// If you need to do something while loading these pages...
#pragma mark UIWebView delegate methods
- (void)webViewDidStartLoad:(UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// finished loading, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// load error, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// report the error inside the webview
NSString* errorString = [NSString stringWithFormat:
@"<html><center><font size=+4 color='red'>The web page is not available. Error description:<br>%@</font></center></html>",
error.localizedDescription];
// Web view:
[self.view loadHTMLString: errorString baseURL: nil];
}
{
// Get your UIWebView, for example:
UIWebView *myView = (UIWebView *)self.view;
myView.delegate = self; // To be sure...
[myView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.weston-fl.com/"]];
}
// If you need to do something while loading these pages...
#pragma mark UIWebView delegate methods
- (void)webViewDidStartLoad:(UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// finished loading, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// load error, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// report the error inside the webview
NSString* errorString = [NSString stringWithFormat:
@"<html><center><font size=+4 color='red'>The web page is not available. Error description:<br>%@</font></center></html>",
error.localizedDescription];
// Web view:
[self.view loadHTMLString: errorString baseURL: nil];
}
// ...
// Delayed preload
[NSTimer scheduledTimerWithTimeInterval: 2.0f
target: self
selector: @selector(InitViews:)
userInfo: nil
repeats: NO];
}
// Preload tab's remote web pages
- (void) InitViews: (NSTimer *) timer
{
UITabBarController *myTabBar = self.tabBarController; // this is the tab bar from the nib file
NSArray *myViewControllers = myTabBar.viewControllers;
if( myViewControllers && [myViewControllers count] > 3 ){
SecondViewController *ctrl2 = (SecondViewController *)[myViewControllers objectAtIndex: 1];
[ctrl2 LoadMyWebView]; // direct method call
ThirdViewController *ctrl3 = (ThirdViewController *)[myViewControllers objectAtIndex: 2];
[ctrl3 LoadMyWebView]; // direct method call
// UIWebView *view = (UIWebView *)ctrl2.view; // access the view property if you want
}
}