Tôi đã thử cách này một lúc, nhưng tôi không hiểu đúng.Tạo UIWebView theo chương trình
Tôi đã viết hàm init sau đây trong một tập tin hỗ trợ:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 1024,768)];
}
return self;
}
và sau trong ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *view = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
NSString *[email protected]"http://www.google.com";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[view loadRequest:nsrequest];
}
Tôi cũng đã cố gắng tạo ra webview trong didFinishLaunchingWithOptions:
phương pháp appdelegate, nhưng nó cũng không hoạt động.
Cách chính xác là gì?
nhờ trả lời của bạn, nhưng im nhận được lỗi trên self.view – user1153798
@ user1153798 nếu mã là trong 'UIViewController',' self.view' nên khỏe. '.view' có thể sai - hãy thử' [self.view webview] 'thay vào đó (xem phần chỉnh sửa). – dasblinkenlight