1

构建时出现 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*'

如果需要,您可以在此处找到 ViewControllerm ViewControllerh AppDelegatem 的文本文件http://ninjabreakbot.com/stack/

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

谢谢!

4

2 回答 2

5

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

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

于 2012-04-13T04:23:50.437 回答
2

检查initWithNibName。是 nib 文件名ViewController还是其他名称?

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

写入@synthesize viewController ;AppDelegate.m 文件

.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
于 2012-04-13T04:58:42.480 回答