【问题标题】:Build Error - Receiver type "ViewController" for instance messages is a forward declaration构建错误 - 例如消息的接收器类型“ViewController”是前向声明
【发布时间】:2012-04-13 04:13:29
【问题描述】:

我在构建时遇到 2 个错误,它们位于 AppDelegatem 文件中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

有两个错误的行:

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

错误1:

Receiver type "ViewController" for instance messages is a forward declaration

错误2:

Receiver "ViewController" for class messages is a forward declaration

带有警报的行:

self.window.rootViewController = self.viewController;

提醒:

Incompatible pointer types assigning to 'UIViewController *' from 'ViewController*'

如果需要,您可以找到以下文本文件 视图控制器 视图控制器 AppDelegatem 这里http://ninjabreakbot.com/stack/

项目适用于 iOS5,我对此很陌生。请让我知道这样的问题有什么用处。或者,如果提供的足够多,您的解决方案!

谢谢!

【问题讨论】:

    标签: iphone ios5 compiler-errors


    【解决方案1】:

    错误消息:instance messages is a forward declaration 通常意味着您的编译器不知道该类的声明,即您没有包含正确的标头。

    在你的情况下,在 AppDelegate.m 的开头写 #import <ViewController.h> 应该可以解决这个编译器问题。

    【讨论】:

    • 我的 AppDelegate.m 文件包含 #import "ViewController.h" 行有一个指向我的文件的链接,您可以在我的帖子中查看,非常感谢您的帮助。
    • 这个答案确实帮助我解决了与类别相关的问题。谢谢!
    【解决方案2】:

    检查initWithNibName。 nib文件名是ViewController还是别的名字?

    #import "ViewController.h"@property (strong, nonatomic) ViewController *viewController; 在 AppDelegate.h 文件中

    在 AppDelegate.m 文件中写入@synthesize viewController ;

    .h 文件::

    #import <UIKit/UIKit.h>
    #import "ViewController.h"
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    @property (strong, nonatomic) ViewController *viewController;
    
    @end
    

    .m 文件::

    #import "AppDelegate.h"
    #import "ViewController.h"
    
    @implementation AppDelegate
    
    @synthesize window;
    @synthesize viewController ;
    
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
    
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    @end
    

    【讨论】:

    • 我的 .xib 被称为 ViewController 添加这些行并不能解决任何错误 #import "ViewController.h" 不在我的 AppDelegate.h 文件中,但是您提到的下一行是。还添加了 @synthesize viewController ;在 AppDelegate.m 文件中给出错误(非法接口限定符)谢谢您的帮助。
    • nib 文件名看起来像 X-code 项目导航器中的 ViewController.xib。
    • @PrasadG 我得到了这个错误.. 我必须做什么.. 请指导我,我在另一个视图中得到这个,我想调用一个方法
    • @Babul:我有什么可以帮助你的吗?给我简单解释一下。
    • @PrasadG 我在我的应用程序中这样做了 #ifdef __cplusplus #import #import "OpenCVClientViewController.h" #endif 我需要调用 "OpenCVClientViewController" 中的方法它给了我上面发布的错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多