0

下面的代码在 Iphone 上运行,我在 ipad 上加载 webview 时遇到问题,它遇到了 didFailwith 错误,(iPad 已连接)有什么帮助吗?

 - (void)viewDidAppear:(BOOL)animated
{
      NSURL *url;
      if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
          url = [NSURL URLWithString:@"http://www.google.com"];
      }else{
          url = [NSURL URLWithString:@"http://www.google.com"];
      }
      NSURLRequest *req = [NSURLRequest requestWithURL:url]; 
      [webSurfForecast loadRequest:req];
      [super viewDidAppear:YES];
  }

 -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Can't connect. Please check your          internet Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
4

1 回答 1

1

你可以这样检查..

  BOOL iPad = NO;
  #ifdef UI_USER_INTERFACE_IDIOM
  iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
  #endif
  if (iPad) {
            // iPad specific code here
   } else {
            // iPhone/iPod specific code here
   }
于 2012-04-11T10:34:53.377 回答