0

我正在实现一个基本上加载网页的应用程序(适用于 iphone 和 ipad)。iPhone 的 webview 加载正确,但 iPad WebView 什么也没做?!

这是我的 ViewController.m

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIWebView *webViewiPad;

@end

@implementation ViewController
@synthesize webView = _webView;
@synthesize webViewiPad = _webViewiPad;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.at"]]];
    [self.webViewiPad loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.at"]]];
}
4

1 回答 1

0

加载 ViewController 时执行以下操作:

 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

   self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
  }
 else
 {
   self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
 }

将 webViewiPad 绑定到 iPad Xib 和 webView 分别绑定到 iPhone Xib

 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //load differnt xib according to iphone and ipad
{
    [self.webViewiPad loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.at"]]];

 }
 else
 {
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.at"]]];

 }
于 2012-09-01T12:24:12.633 回答