Webview适用于iphone,但适用于ipad

时间:2012-04-11 10:27:28

标签: iphone ios ipad mobile ios5

下面的代码正在开发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];
}

1 个答案:

答案 0 :(得分: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
   }