如果 UIWebview url 等于 [英] If UIWebview url is equal to
问题描述
我有一个名为homeview"的 UIWebView.每次有人浏览 UIWebview 时,我都想检查页面 url 是否为 "http://www.website.com/cart",然后将标签控制器更改为第二个标签.
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.
所以我是这样做的:
- (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...
上面的代码放在我的 FirstViewController.m 中,这是我的 FirstViewController.h:
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
谁能帮帮我?
推荐答案
试试这个:
使用*Compare:*比较两个字符串.
Use *Compare:*to compare two strings.
- (BOOL)webView:(UIWebView *)homeview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
if ([URLString Compare:@"http://www.website.com/cart"]==NSOrderedSame) {
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:2];
}
return YES;
}
这篇关于如果 UIWebview url 等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!