gpt4 book ai didi

ios - 如果 UIWebview url 等于

转载 作者:行者123 更新时间:2023-12-01 18:18:52 24 4
gpt4 key购买 nike

我有一个名为“homeview”的 UIWebView。每次有人浏览 UIWebview 时,我想检查页面 url 是否为“http://www.website.com/cart”,然后将选项卡 Controller 更改为第二个选项卡。

所以我这样做了:

- (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;
}

但是没有运气......所以我试图在页面等于 url 时收到警报:
- (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;
}

但这也不是诀窍......

上面的代码放在我的 FirstViewController.m 中,这是我的 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:* 比较两个字符串。

- (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;
}

关于ios - 如果 UIWebview url 等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18846469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com