0

我正在學習ObjC和可可開發,並且遇到了一個真正的'stumper'。用盡了谷歌,我恭敬地裝飾我的絕望帽子,呈現給大家:接收器類型'WebFrame',例如消息是一個前向聲明

類和視圖控制器:

類「內容窗口」導入一個視圖控制器實例,並把它放在一個窗口:

ContentWindow.h

#import <Foundation/Foundation.h> 
#import <WebKit/WebView.h> 
#import "ContentViewController.h" 
@interface ContentWindow : NSWindow{ 
    ContentViewController* viewController; 
} 
@property IBOutlet ContentViewController* viewController; 
-(NSWindow *) newWindow; 
@end 

ContentWindow.m

#import "ContentWindow.h" 
@implementation ContentWindow 

@synthesize viewController; 
-(NSWindow *) newWindow{ 
    //Builds the window as 'window' and displays it successfully here 
    //... [code redacted for brevity] 

    // Build view 
    viewController = [[ContentViewController alloc] initWithNibName:@"ContentViewController" bundle:nil]; 
    [window setContentView: viewController.view]; 
    NSString *urlString = @"http://www.google.com"; 
    [[viewController.webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]]; 
    [viewController.title setStringValue:@"my title"]; 
} 
@end 

我試圖做兩件事情與接口:

[viewController.title setStringValue:@"my title"]; 

這成功地將視圖元素「標題」爲「我的標題」。

[[viewController.webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]]; 

然而,這引發錯誤:

Receiver type 'WebFrame' for instance message is a forward declaration. 

並以紅色突出了線的部分:

viewController.webView mainFrame 

我的視圖控制器被如下:

ContentViewController.h

#import <Cocoa/Cocoa.h> 
#import <WebKit/WebView.h> 
@interface ContentViewController : NSViewController { 
    IBOutlet NSTextField *title; 
    IBOutlet WebView *webView; 
} 
@property IBOutlet WebView *webView; 
@property IBOutlet NSTextField *title; 
@end 

ContentViewController.m

#import "ContentViewController.h" 
@interface ContentViewController() 
@end 
@implementation ContentViewController 
@synthesize title, webView; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
    } 
return self; 
} 
@end 

最後使用這個類,我從我的AppDelegate類實例化一個內容窗口

contentWindow = [[ContentWindow new] newWindow]; 

已經進口ContentWindow.h到AppDelegate.h和將其具有:

__strong NSWindow * contentWindow 

作爲AppDelegate合成的實例變量。

我已經鏈接了IB中的兩個項目(絕對是!)我還在我的項目中添加了Webkit基礎,這是在另一個線程中建議的。

我不能爲了我的生活理解發生了什麼。我知道合乎邏輯的答案是放下Xcode,然後拿起'學習Xcode和Objective C'書(帶有一個書籤,大概在我足夠傲慢的地方,認爲我已經學會了足夠的嘗試),但是在我這樣做之前,在機會之外:

任何人都可以幫忙嗎?

一如既往的感謝,AtFPt。

回答

1

通常這個錯誤信息意味着類的類型不知道(因爲由@class聲明)。 請確保您的代碼可以看到WebFrame的聲明。 如果是這樣,也許你稍後添加它,XCode使用舊的元數據。在這種情況下,建立前的清理通常會有所幫助。

+0

我在本附錄中標記爲正確:搜索'WebFrame'類,發現它是的一部分,看到我正在導入。將WebKit添加到導入。第一次工作。謝謝。 –

相關問題