大家好我正在尝试加载一个html页面,加载后我想要执行change.php?lang=eng
。
程序启动时我现在有了这个:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Treviturismo.it";
link = @"http://www.treviturismo.it/dev/index.php";
NSURL *url = [NSURL URLWithString:link];
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
}
也许我可以使用IF检查页面是否已加载,然后:
link = @"http://www.treviturismo.it/dev/change.php?lang=en";
NSURL *url = [NSURL URLWithString:link];
requestObj=[NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
这是一个好方法吗?我不知道在if()
输入什么,以检查第一页是否已加载!
谁能帮我?
谢谢!
答案 0 :(得分:1)
您应该使用UIWebViewDelegate
协议来监听页面加载事件。
- (void)viewDidLoad
{
[super viewDidLoad];
// init code...
myWebView.delegate = self; // your class must implement the UIWebViewDelegate protocol
link = @"http://www.treviturismo.it/dev/index.php";
NSURL *url = [NSURL URLWithString:link];
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// if you want this method to not being called again, do this :
webView.delegate = nil;
// then do your request to change.php here
link = @"http://www.treviturismo.it/dev/change.php?lang=en";
NSURL *url = [NSURL URLWithString:link];
requestObj=[NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}