I got a UIWebView called "homeview". Everytime someone is browsing the UIWebview I want to check if the page url is "http://www.website.com/cart" and then change the tab controller to the second tab.
So I did it like this:
- (BOOL)webView:(UIWebView *)homeview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
if ([URLString isEqualToString:@"http://www.website.com/cart"]) {
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:2];
}
return YES;
}
But with no luck... So I tried to get an alert when page is equal to the url with:
- (BOOL)webView:(UIWebView *)homeview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
if ([URLString isEqualToString:@"http://www.website.com/cart"]) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Alert Title here"
message: @"Alert Message here"
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
[alert show];
[alert release];
}
return YES;
}
But that didn't the trick as well...
The above code is placed in my FirstViewController.m and this is my FirstViewController.h:
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
{
IBOutlet UIActivityIndicatorView *indicator;
IBOutlet UIWebView *homeview;
NSTimer *timer;
}
@property (retain, nonatomic) IBOutlet UIWebView *homepage;
@end
Anyone who can help me out?