在前向类中找不到属性“框架” [英] Property 'frame' cannot be found in forward class

查看:62
本文介绍了在前向类中找不到属性“框架”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:我对可可粉的开发很陌生。我想我的问题很明显。

First: I'm very new to cocoa development. I guess my problem is something very obvious.

加载后,我需要知道WebView的大小。为此,我已经找到了答案,但是我遇到了问题。这是我代码的相关部分。

I need to know the size of my WebView after loading. For that I've found the answer already, but I have a Problem. Here's the relevant piece of my code.

应用程序委托:

    @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;
      }
    }

window属性在应用程序委托:

The window property is defined in the header file of the app delegate:

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

我找到了非常相似的问题。那里的解决方案是 #import< QuartzCore / QuartzCore.h> ,并在构建阶段选项卡中链接框架。我这样做了,但问题仍然存在。我也清理了我的项目(到目前为止,我仍然不十分了解清理的作用,但有时它会有所帮助)。

I found the answer to (so it would seem) a very similar problem. The solution there is to #import <QuartzCore/QuartzCore.h>and also link the framework in the Build Phases tab. I did this, but the problem remains. I also cleaned my project (as of now I still don't really know what cleaning does, but sometimes it helps) with no result.

该窗口是我自己的类 TransparentWindow 继承了 NSWindow 。当我开始在子类实现文件中编写 self.f 时,xcode会自动建议 frame 。但是,当我在 webView:didFinishLoadForFrame 方法中编写 self.window.f 时,不会发生这种情况。

The window is an instance of my own class TransparentWindow which is subclassing NSWindow. When I start writing self.f in the subclass implementation file xcode automatically suggests frame. But this is not happening when I write self.window.f in the webView:didFinishLoadForFrame method.

正如我所说,我是可可开发的新手。有什么提示,我可能错过了什么?

As I said, I'm new to cocoa development. Any hints, what I might have missed?

推荐答案

如果只对类进行前向声明,通常会收到此消息,例如

You usually get this message if you only did a forward declaration of a class, like

@class MyPhantasticClass;

编译器知道它是一个类,但是不知道任何方法。您需要包括正确的头文件。

The compiler knows that it is a class, but doesn't know any of it's methods. You need to include the right header file.

这篇关于在前向类中找不到属性“框架”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆