如何为网络浏览器创建历史记录

发布于 2025-01-04 20:13:09 字数 617 浏览 1 评论 0原文

我正在为 iPad 制作自己的网络浏览器,在尝试创造历史时遇到了问题。代码如下:

.m
-(void)viewDidLoad{
[self historyMethod];
//more settings...
}

-(void)historyMethod{
NSString *googleString= @"http://www.google.es";
    NSString *currentURLString=TextField.text;
    [historyArray addObject:googleString];
    if ([googleString isEqual: currentURLString]) {
        googleString = nil;
        [TableView reloadData];
    }


    [historyArray addObject: currentURLString ];
    [TableView reloadData];

}

我遇到的问题是 historyMethod 仅执行一次,而我需要它一直工作!由于我是新手,我不太了解方法,也不知道如何让它发挥作用。我用 while 循环尝试过,但没有成功。请帮助我的人!

I'm making my own web browser for the iPad, and I have a problem while I'm trying to make the history. Here's the code:

.m
-(void)viewDidLoad{
[self historyMethod];
//more settings...
}

-(void)historyMethod{
NSString *googleString= @"http://www.google.es";
    NSString *currentURLString=TextField.text;
    [historyArray addObject:googleString];
    if ([googleString isEqual: currentURLString]) {
        googleString = nil;
        [TableView reloadData];
    }


    [historyArray addObject: currentURLString ];
    [TableView reloadData];

}

The problem that I have is that the historyMethod is executed just one time, and I need it working all the time! Since I'm a newbie, I don't know too much about methods, and how I can make it work well. I tried it with a while loop but it didn't work. Please help me people!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风情万种。 2025-01-11 20:13:09

您的意思是您希望重复调用该方法?
您可以使用 NSTimer 之类的东西来重复方法调用;

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(historyMethod) userInfo:nil repeats:YES];

这将每 1 秒调用您的方法,将其放入您的 viewDidLoad 方法中,而不是调用您的 historyMethod

然而,如果你不理解方法,我建议你寻找一些 Objective-C 教程。

You mean you want the method to be called repeatedly?
you can use something like NSTimer to repeat a method call;

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(historyMethod) userInfo:nil repeats:YES];

This will call your method every 1 seconds, place this in your viewDidLoad method, instead of calling your historyMethod.

However, if you don't understand methods, I'd recommend some looking for some Objective-C tutorials.

一梦浮鱼 2025-01-11 20:13:09

如果您使用的是 UIWebView,那么您可能想让您的控制器成为 UIWebViewDelegate

通过实现 - (void)webViewDidFinishLoad:(UIWebView *)webView 你可以跟踪
正在加载的页面数。在此委托方法中,您可以通过 webview.request.URL 获取 URL

看一下:

UIWebViewDelegate

UIWebViewDelegateProtocol

NSURLRequest

If you're using UIWebView then you might wanna make your controller a UIWebViewDelegate.

By implementing - (void)webViewDidFinishLoad:(UIWebView *)webView you could keep track
of pages being loaded. Inside this delegate method you can get URL by webview.request.URL

Take a look at:

UIWebViewDelegate

UIWebViewDelegateProtocol

NSURLRequest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文