gpt4 book ai didi

ios - 我可以在没有 goBack 导航的情况下获取 UIWebView 的以前的 url 吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:18 25 4
gpt4 key购买 nike

如果是UIWebView canGoBack,我可以在没有返回导航的情况下获取之前的url吗?

我知道我可以自己实现一个历史堆栈,但我相信 UIWebView 会维护一个历史堆栈,因此它可以前后移动。有没有办法访问此历史记录?

编辑:我的意思是:有没有办法从 UIWebView 访问此历史记录?

最佳答案

我喜欢 RAJA 所说的关于将 URL 存储在 NSArray 中的想法,但他并没有真正实现它,所以现在就开始吧。

MySubClass.h

@interface MySubClass : MySuperClass

// I am assuming that you are creating your UIWebView in interface builder
@property (nonatomic, strong) IBOutlet UIWebView *myWebView;

// I'm going to make the initial array that stores the URLs private to
// this class but if we wanted to access that array outside of this class
// we can using this method, but we will return a NSArray not a NSMutableArray
// so it can't be modified outside of this class.
- (NSArray *)visitedURLs;

@end

MySubClass.m

#import "MySubClass.h"

// Our private interface
@interface MySubClass()

// Our private mutable array
@property (nonatomic, strong) NSMutableArray *visitedURLsArray;

@end

@implementation MySubClass

- (void)viewDidLoad
{
// Check if the visitedURLsArray is nil and if it is alloc init
if(visitedURLsArray == nil)
visitedURLsArray = [[NSMutableArray alloc] init];
}

- (NSArray *)visitedURLs
{
return (NSArray *)visitedURLsArray;
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// If you don't wish to store the URL every time you hit refresh where you
// could end up with the same URL being add multiple times you could also
// check what the last URL was in the array and if it is the same ignore it
if(![[visitedURLsArray lastObject] isEqualToString:[[request URL] absoluteString]]) {

// Every time this method is hit, so every time a request is sent into the
// the webView. We want to store the requested URL in the array.
// so this would create a log of visited URLs with the last one added being
// the last URL visited.
[visitedURLsArray addObject:[[request URL] absoluteString]];
}
return YES;
}

@end

重要提示

此答案基于原始问题,该问题未提及与用户正在使用的 backbone.js 有任何关系。

关于ios - 我可以在没有 goBack 导航的情况下获取 UIWebView 的以前的 url 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22529472/

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