如何使WebView OSX Xcode项目在启动时加载URL? [英] How to make WebView OSX Xcode project load a URL on launch?

查看:96
本文介绍了如何使WebView OSX Xcode项目在启动时加载URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在尝试学习如何开发Mac应用程序.我已经完成了所有网络浏览器的制作,但是我真的很想知道如何使WebView加载URL(让我们说 http://google.com/).我该怎么办?

Okay, well I am trying to learn how to develop mac apps. I have done making a web browser and all, but I really want to know how to make the WebView load a URL (lets say http://google.com/) when the apps start. How do I do that?

推荐答案

在您的应用程序委托中,实现

In your app delegate, implement

-(void)applicationDidFinishLaunching:(NSNotification*) notification
{
     ....
}

当应用程序确实完成启动时,可可系统会自动将该方法称为 ,对吧?

This method is called automatically by the Cocoa system when the app did finish launching, quite obvious, right?

假设您的应用程序委托中有IBOutlet WebView*webview.然后,您要做的就是在applicationDidFinishLaunching:内部调用

Suppose you have IBOutlet WebView*webview in your app delegate. Then all you have to do is, inside applicationDidFinishLaunching:, to call

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

仅此而已!

这篇关于如何使WebView OSX Xcode项目在启动时加载URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆