2014-02-24 25 views
0

第一:我對可可開發很陌生。我想我的問題是非常明顯的。在前列類別中找不到屬性「框架」

加載後我需要知道我的WebView的大小。爲此,我已經找到了answer,但是我有一個問題。這是我的代碼的相關部分。

應用程序的委託:

@implementation MDAppDelegate 

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 

     //set ourselves as the frame load delegate so we know when the window loads 
     [self.webView setFrameLoadDelegate:self]; 

     // set the request variable, which works and then load the content into the webView 
     [self.webView.mainFrame loadRequest:request]; 

    } 

    - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)webFrame 
    { 
     NSLog(@"webView:didFinishLoadForFrame"); 
     if([webFrame isEqual:[self.webView mainFrame]]) { 
     // some code ... 
     // and at some point I want to get the frame property of self.window 
     NSRect windowFrame = self.window.frame; 
     } 
    } 

窗口屬性在應用程序委託的頭文件中定義:

@interface MDAppDelegate : NSObject <NSApplicationDelegate> 
     @property (weak) IBOutlet MDTransparentWindow *window; 
     @property (weak) IBOutlet WebView *webView; 
    @end 

我找到了答案,(所以它似乎)一個very similar problem。解決方案存在於#import <QuartzCore/QuartzCore.h>,並且還可以在「構建階段」選項卡中鏈接框架。我這樣做了,但問題依然存在。我還清理了我的項目(截至目前,我仍然不清楚清潔是幹什麼的,但有時候它有幫助),但沒有結果。

該窗口是我自己類TransparentWindow的一個實例,它是子類NSWindow。當我開始在子類實現文件self.f中寫入xcode時,會自動建議frame。但是,當我在webView:didFinishLoadForFrame方法中編寫self.window.f時,不會發生這種情況。

正如我所說,我是可可開發新手。任何提示,我可能錯過了什麼?

+0

你編譯代碼嗎?這只是一個不工作自動完成的問題? – RaffAl

+0

它不編譯。 Xcode還向我顯示了在我使用'self.window.frame'和相應行的錯誤消息中出現的錯誤。 – beipawel

回答

1

你通常得到這個消息,如果你只是做了一個類的前向聲明,像

@class MyPhantasticClass; 

編譯器知道,這是一類,但不知道它的任何的方法。你需要包含正確的頭文件。

+0

謝謝。我在應用程序delagate文件中包含了我的NSWindow子類的頭文件,現在它可以工作。 – beipawel