我在构建时遇到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,我对此非常陌生。请让我知道对此类问题有用的内容。或者,如果已经提供了足够的解决方案!
谢谢!
答案 0 :(得分:5)
错误消息:instance messages is a forward declaration
通常意味着编译器不知道类的声明,即您没有包含正确的标题。
在你的情况下,在AppDelegate.m的开头写#import <ViewController.h>
应解决这个编译问题。
答案 1 :(得分:2)
检查initWithNibName
。是nib文件名ViewController
还是其他名称?
写#import "ViewController.h"
和
AppDelegate.h文件中的@property (strong, nonatomic) ViewController *viewController;
在AppDelegate.m文件中写@synthesize viewController ;
.h file ::
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
.m file ::
#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