【问题标题】:Receiver type 'WebFrame' for instance message is a forward declaration例如消息的接收器类型“WebFrame”是前向声明
【发布时间】:2012-08-30 10:31:14
【问题描述】:

我正在学习 ObjC 和可可开发,遇到了一个真正的“笨蛋”。筋疲力尽的谷歌,我恭恭敬敬地戴上我的绝望帽子并向你展示:

一个类和一个视图控制器:

“内容窗口”类导入一个视图控制器实例并将其放置在一个窗口中:

内容窗口.h

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

内容窗口.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 基础,这是在另一个线程中建议的。

我一辈子都无法理解发生了什么。但在我这样做之前,碰巧:

有人可以帮忙吗?

一如既往地感谢 AtFPt。

【问题讨论】:

    标签: objective-c xcode cocoa interface-builder forward-declaration


    【解决方案1】:

    通常这个错误信息意味着,一个类的类型是未知的(因为由@class 声明)。 确保您的代码可以看到WebFrame 的声明。 如果是这样,也许你稍后添加它,XCode 可以处理旧的元数据。在这种情况下,构建前的清理通常会有所帮助。

    【讨论】:

    • 我用这个附录将其标记为正确:搜索“WebFrame”类,发现它是 的一部分,看到我正在导入 。将 WebKit 添加到导入中。第一次工作。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多