1

嘿伙计们,我是 iOS 世界的新手,所以请多多包涵。

我创建了一个 webview 来制作 iOS 原生的 web 应用程序,并且该应用程序目前在商店中。但是,一些用户在连接丢失/慢速时遇到了重新加载视图(在警报消息中)的问题。我使用“网络链接调节器”工具对其进行了测试,在连接速度较慢的情况下,即使您尝试刷新页面,警报也会不断弹出。下面是我的代码,希望你能帮我解决这个问题。

//Overide the default error message by adding error handling mecanism
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                message:@"You must be connected to the internet to use HIPPOmsg. Try again or click the home button to quit"
                                               delegate:self
                                      cancelButtonTitle:@"Try again"
                                      otherButtonTitles:nil];
[alert show];
[alert release];
}

//Implement the 'Try again' button action
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
    NSURL *url = [NSURL URLWithString:@"https://app.hippomsg.com/home.php"];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [webView loadRequest:req];
}
}
4

1 回答 1

0

You alert has only 1 button, and u have a method definition set to that button. So obviously every time u click the alert button, UIAlerview delegate will be called and it will keep trying again and again (until ur internet actually works).

So provide 2 buttons as per u alert message, "Try Again" and "Home". So "Try Again" will perform ur method wat u have given, "Home" wills top searching and quit the process.

于 2012-09-19T16:59:01.347 回答