如何为网络浏览器创建历史记录
我正在为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的意思是您希望重复调用该方法?
您可以使用 NSTimer 之类的东西来重复方法调用;
这将每 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;This will call your method every 1 seconds, place this in your
viewDidLoad
method, instead of calling yourhistoryMethod
.However, if you don't understand methods, I'd recommend some looking for some Objective-C tutorials.
如果您使用的是
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 aUIWebViewDelegate
.By implementing
- (void)webViewDidFinishLoad:(UIWebView *)webView
you could keep trackof pages being loaded. Inside this delegate method you can get URL by
webview.request.URL
Take a look at:
UIWebViewDelegate
UIWebViewDelegateProtocol
NSURLRequest