iphone应用程序DidFinishLaunching问题
你好 我对 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
Hello
I have problem with didFinishLaunching methods. I am really getting confused about what was the problem and that's why I pasted all my code. The problem was the application didn't launch, it crashed, and it show me this message in console:
**[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'**
I am using this code
In Demo1appDelegate.h file
#import <UIKit/UIKit.h>
#import "MapViewController.h"
@interface Demo1AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MapViewController *mapViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
And in
Demo1AppDelegate.m file
#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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我认为
是问题所在。您没有
mapViewController
的@synthesize
。所以你无法通过self
访问或者另一个选择是尝试这个
I think
is the problem. You do not have
@synthesize
formapViewController
. So you cannot access throughself
Or another option is to try this
您需要将 UIApplication
更改
为
这将解决您的问题
You need to implement UIApplication
change
to
This will solve your problem
问题出在这一行
self.mapViewController = viewController;
你忘记了
@synthesize mapViewController;
the problem is in this line
self.mapViewController = viewController;
you forgot
@synthesize mapViewController;
合成您的地图视图控制器。
Synthesize your map view controller.
您必须在 Demo1AppDelegate.m 中添加
@synthesize mapViewController;
您还应该在 Demo1AppDelegate.m 的
dealloc
方法中添加[mapViewController release];
(其中mapViewController是一个实例变量)。You have to
@synthesize mapViewController;
in Demo1AppDelegate.mYou should also add
[mapViewController release];
in thedealloc
method of Demo1AppDelegate.m (with mapViewController being an instance variable).添加委托如下...这可能是问题所在:
@interface Demo1AppDelegate : NSObject
Add delegate as follows ... This might be the issue :
@interface Demo1AppDelegate : NSObject <UIApplicationDelegate>
添加
尝试在 Demo1AppDelegate.h 中的 @implementation Demo1AppDelegate 之前
Try adding
before @implementation Demo1AppDelegate in Demo1AppDelegate.h
嘿!在哪里添加子视图
尝试不使用“self”
只是一个猜测。
Hey! Where you add the subview
Try without "self"
Just a flying guess.