UIWebView 不加载 URL ,iOS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15611204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIWebView doesnt load URL , iOS
提问by donparalias
I am trying to load a URL when my app starts.
我正在尝试在我的应用程序启动时加载 URL。
I dragged an UIWebView Object , on my .nib , i created a property outlet , i connected it to the webview and in my view controller i place the following code :
我拖了一个 UIWebView 对象,在我的 .nib 上,我创建了一个属性插座,我将它连接到 webview 并在我的视图控制器中放置以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = @"http://google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
However i just get a black screen on the device , like theres no view at all. Any idea?
但是我只是在设备上看到黑屏,就像根本看不到一样。任何的想法?
回答by Premsuraj
This is the code I'm using in my application
这是我在应用程序中使用的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSURL *websiteUrl = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[myWebView loadRequest:urlRequest];
}
回答by Sukeshj
This is short one
这是短的
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
}
回答by Devendra
Restart your IOS simulator. It is really not evident, but check, at first, any site in Safari at IOS simulator. After restart of IOS simulator, my webView opened successfully both at simulator and device.
重启你的 IOS 模拟器。这确实不明显,但首先检查 IOS 模拟器中 Safari 中的任何站点。IOS模拟器重启后,我的webView在模拟器和设备上都成功打开了。
By Amit
由阿米特