所以,我一直在尋找文檔和谷歌搜索,但我無法弄清楚當我的WebView(OSX,不是iOS)更改時如何調用方法...所有示例似乎是iOS的。我的代碼如下所示:WebView更改時的調用函數
SNAFAppDelegate.h
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface SNAFAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet WebView *browser;
- (IBAction)forwards:(id)sender;
@end
SNAFAppDelegate.m
#import "SNAFAppDelegate.h"
@implementation SNAFAppDelegate
@synthesize window = _window;
@synthesize browser = _b;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[_b mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google.com"]]];
}
@end
SNAFBrowser.h
#import <Cocoa/Cocoa.h>
#import <WebKit/WebView.h>
#import <WebKit/WebFrame.h>
#import <WebKit/WebEditingDelegate.h>
#import <WebKit/WebKit.h>
@interface SNAFBrowser : WebView
@property (assign) IBOutlet WebView *browser;
@end
SNAFBrowser.m
#import "SNAFBrowser.h"
@implementation SNAFBrowser
@synthesize browser = _b;
- (void)webViewDidChange:(NSNotification *)notification
{
NSLog(@"Hello World");
}
@end
然後,在我的MainMenu.xib文件中,我將AppDelegate的Outlet「browser」鏈接到WebView,並將WebView的自定義類設置爲SNAFBrowser。
本質上,我只是想知道什麼時候webview加載另一個頁面。
我可能在做一些荒謬愚蠢的事情,所以任何幫助表示讚賞。
此方法是WebEditingDelegate協議的,則需要確認該協議並設置委託給自己。 – rishi
我剛剛嘗試在webViewDidChange方法中添加'[_b setDelegate:self];'但它給了我'沒有可見的'WebView'的@interface聲明選擇器'setDelegate:'您是通過確認協議的意思嗎? – citruspi