【发布时间】:2014-04-01 08:03:53
【问题描述】:
我正在创建一个应用程序,它使用 WebView 从 Web 加载内容,但 WebView 没有显示给用户,我想知道页面何时完成加载,为此,我将使用 didFinishLoadForFrame 但要让这件事工作I saw that :
您需要将您的 webView 对象的 outlet frameLoadDelegate 设置为 类,其中包含一个方法 webView:didFinishLoadForFrame:
我的问题是,如果不使用 Interface Builder,我不知道该怎么做……我应该写什么代码,应该在哪里写?
这里是 AppDelegate.h 的内容
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet WebView *myWeb;
@end
这里是 AppDelegate.m 的内容
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[self.myWeb mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]];
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
NSLog(@"La page a été chargée !");
}
@end
谢谢
【问题讨论】:
-
顺便说一句,我是 Objective-C 编程的新手...
标签: objective-c macos webview osx-mavericks