我在YouTube上观看了此视频: Xcode如何为iOS应用程序创建Webview
我关注了视频,但是如果我在模拟器上运行我的应用程序,只会看到白屏。
这个ViewController.h
//
// ViewController.h
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIWebView *myWebView;
}
@end
//
// ViewController.m //
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *myURL = [NSURL URLWithString:@"http://website.com"]; NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL]; myWebView.scalesPageToFit = YES; [myWebView loadRequest:myRequest];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
你能让我解决这个错误吗?
答案 0 :(得分:0)
是ViewController.m
//
// ViewController.m
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *myURL = [NSURL URLWithString:@"http://website.com"]; NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL]; myWebView.scalesPageToFit = YES; [myWebView loadRequest:myRequest];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 1 :(得分:0)
创建后,您必须实际加载请求!
NSURL *url = [NSURL URLWithString:@"http://yoururl.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];