Webview适用于iphone,但不适用于ipad
下面的代码在Iphone上运行,我在ipad上加载webview时遇到问题,它遇到了错误,(ipad已连接)感谢您的帮助吗Webview适用于iphone,但不适用于ipad,iphone,ios,ipad,mobile,ios5,Iphone,Ios,Ipad,Mobile,Ios5,下面的代码在Iphone上运行,我在ipad上加载webview时遇到问题,它遇到了错误,(ipad已连接)感谢您的帮助吗 - (void)viewDidAppear:(BOOL)animated { NSURL *url; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { url = [NSURL URLWithString:@"http:
- (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];
}
你可以这样检查
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
}
您是否检查了NSError错误变量中的实际内容?嗨,Bastian,新到足以说明这一点,NSError是:error ipad error Domain=webkiterrodomain Code=101“操作无法完成。(webkiterrodomain error 101)。”UserInfo=0x7064c50{}您实际在尝试吗?这个错误听起来像是你在使用一个没有url编码的url。嗨,Anshul,这个答案与我的问题无关,我的代码用来检查设备是否正常工作。