2012-09-19 39 views
1

嘿家伙我是iOS新手,所以请耐心等待。iOS - 在缓慢/有损连接上的UIWebView刷新问题

我创建了一个webview为了使一个网络应用程序原生的iOS和应用程序当前在商店。 但是,有些用户在重新加载有损/慢速连接的视图(在警报消息中)时遇到问题。我使用'网络链接调节器'工具对其进行了测试,并在慢速连接时即使尝试刷新页面时也会弹出警告。 下面是我的代码,希望你能帮我解决这个问题。

//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]; 
} 
} 

回答

0

你提醒只有一个按钮,你有一个方法定义设置为该按钮。 所以很显然,每次你点击提醒按钮,UIAlerview委托将被调用,它会不断尝试一次又一次(直到你的互联网实际工作)。

因此,请按照u警报消息“再试一次”和“首页”提供2个按钮。因此,“再试一次”将执行您给予的方法,“家庭”将搜索并退出该过程。

+0

感谢您的帮助 – fab327