您好 我有didFinishLaunching方法的问题。我真的对这个问题感到困惑,这就是我粘贴所有代码的原因。问题是应用程序没有启动,它崩溃了,它在控制台中显示了这条消息:
**[Demo1AppDelegate setMapViewController:]: unrecognized selector sent to instance 0x5649a30
2011-05-25 14:17:58.724 Demo1[10630:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Demo1AppDelegate setMapViewController:]: unrecognized selector sent to instance 0x5649a30'**
我正在使用此代码 在Demo1appDelegate.h文件中
#import <UIKit/UIKit.h>
#import "MapViewController.h"
@interface Demo1AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MapViewController *mapViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
并且在 Demo1AppDelegate.m文件
#import "Demo1AppDelegate.h"
@interface Demo1AppDelegate ()
@property (nonatomic, retain) MapViewController *mapViewController;
@end
@implementation Demo1AppDelegate
@synthesize window;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MapViewController *viewController = [[MapViewController alloc] init];
self.mapViewController = viewController;
[viewController release];
[window addSubview:self.mapViewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[mapViewController release];
[window release];
[super dealloc];
}
@end
答案 0 :(得分:4)
我认为
self.mapViewController = viewController;
是问题所在。您@synthesize
没有mapViewController
。因此,您无法通过self
或另一种选择是试试这个
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
mapViewController = [[MapViewController alloc] init];
[window addSubview:mapViewController.view];
[window makeKeyAndVisible];
return YES;
}
答案 1 :(得分:1)
您需要实施UIApplication
更改
@interface Demo1AppDelegate : NSObject
到
@interface Demo1AppDelegate : NSObject < UIApplicationDelegate>
这将解决您的问题
答案 2 :(得分:1)
问题在于此行self.mapViewController = viewController;
你忘记了@synthesize mapViewController;
答案 3 :(得分:1)
你必须在Demo1AppDelegate.m
中@synthesize mapViewController;
您还应该在Demo1AppDelegate.m的[mapViewController release];
方法中添加dealloc
(mapViewController是一个实例变量)。
答案 4 :(得分:1)
合成地图视图控制器。
答案 5 :(得分:0)
添加委托如下......这可能是问题所在:
@interface Demo1AppDelegate : NSObject <UIApplicationDelegate>
答案 6 :(得分:0)
尝试添加
@class MapViewController
在Demo1AppDelegate.h中的@implementation Demo1AppDelegate
之前答案 7 :(得分:0)
喂!添加子视图的位置
[window addSubview:self.mapViewController.view]; [window makeKeyAndVisible];
尝试没有“自我”
[window addSubview:mapViewController.view]; [window makeKeyAndVisible];
只是一个飞跃的猜测。