2011-10-06 85 views
0

首先讓我說我對COCOA非常陌生,但我正在學習。我有一個簡單的網頁瀏覽器。它加載一個默認頁面,從文本字段獲取URL,甚至可以進行谷歌搜索。我正在運行的問題是使用當前URL更新textfeild。我的代碼如下...從WebKit的URL更新文本字段

在.H是...

#import <Cocoa/Cocoa.h> 
#import <WebKit/WebKit.h> 

@interface MustangAppDelegate : NSObject <NSApplicationDelegate> { 
    NSWindow *window; 
    NSTextField *googleSearch; 
    WebView *webView; 
    NSTextField *addressBar; 
} 

@property (assign) IBOutlet NSWindow *window; 
@property (nonatomic, retain) IBOutlet NSTextField *googleSearch; 
@property (nonatomic, retain) IBOutlet WebView *webView; 
@property (nonatomic, retain) IBOutlet NSTextField *addressBar; 

- (IBAction)googleSearch:(id)sender; 
- (IBAction)homeAction:(id)sender; 
- (IBAction)addressBar:(id)sender; 
@end 

在.M我有一堆所以我會在我認爲是與此有關.. 。

#import "MustangAppDelegate.h" 

@implementation MustangAppDelegate 

@synthesize window; 
@synthesize googleSearch; 
@synthesize webView; 
@synthesize addressBar; 

- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { 
    NSURLRequest *currentRequest = [webView request]; 
    NSURL *currentURL = [currentRequest URL]; 
    addressBar.stringValue = currentURL.absoluteString; 
} 

上述方法的代碼永遠不會被調用。就像我說的,我對OBC & Cocoa很陌生,但是已經在Perl這樣的東西上進行了多年的編程。似乎我錯過了一些連接,因爲我收到了上述代碼的警告,指出WebView可能無法響應請求。我周圍挖找到代碼,但它仍然看起來像我想的東西...

感謝 邁克

回答

0

只是CTRL +從IB拖動-frameLoadDelegate到您的應用程序,野馬的應用代表 使用-didFinishLoadForFrame作爲URL ,如果您需要使用標題,則使用-didRecieveTitle。

希望它有幫助!