Xcode Webview 打开 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10938660/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:31:54  来源:igfitidea点击:

Xcode Webview Open Url

xcodeurlwebviewlaunch

提问by Kevin G

I'm trying to develop a web browser that will display a website after the launch . I already red the articles and with i cant seem to get it to work with this code .

我正在尝试开发一个将在启动后显示网站的网络浏览器。我已经把文章写红了,但我似乎无法让它与这段代码一起工作。

NSURL*url=[NSURL URLWithString:@"http://www.google.com"];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
[[webview mainFrame] loadRequest:request];

I'm using the cocoa and the Webkit Framework .

我正在使用可可和 Webkit 框架。

回答by jediob1

Try this:

尝试这个:

- (void)applicationDidFinishLaunching:(NSNotification *)notification{
    NSString *urlText = @"http://google.com";
    [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
    return;
}

if that doesn't work, try this:

如果这不起作用,请尝试以下操作:

- (void)awakeFromNib{
    NSString *urlText = @"http://google.com";
    [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
    return;
}

Good luck! tell me if this works!

祝你好运!告诉我这是否有效!

回答by rishi

Use -

用 -

[webview loadRequest:request];