iphone应用程序DidFinishLaunching问题

发布于 2024-11-09 14:11:34 字数 1545 浏览 0 评论 0原文

你好 我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

攀登最高峰 2024-11-16 14:11:34

我认为

self.mapViewController = viewController;

是问题所在。您没有 mapViewController@synthesize。所以你无法通过 self 访问

或者另一个选择是尝试这个

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    mapViewController = [[MapViewController alloc] init];
    [window addSubview:mapViewController.view];
    [window makeKeyAndVisible];

    return YES;
}

I think

self.mapViewController = viewController;

is the problem. You do not have @synthesize for mapViewController. So you cannot access through self

Or another option is to try this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    mapViewController = [[MapViewController alloc] init];
    [window addSubview:mapViewController.view];
    [window makeKeyAndVisible];

    return YES;
}
隐诗 2024-11-16 14:11:34

您需要将 UIApplication

更改

@interface Demo1AppDelegate : NSObject

@interface Demo1AppDelegate : NSObject  < UIApplicationDelegate>

这将解决您的问题

You need to implement UIApplication

change

@interface Demo1AppDelegate : NSObject

to

@interface Demo1AppDelegate : NSObject  < UIApplicationDelegate>

This will solve your problem

执笏见 2024-11-16 14:11:34

问题出在这一行 self.mapViewController = viewController;

你忘记了 @synthesize mapViewController;

the problem is in this line self.mapViewController = viewController;

you forgot @synthesize mapViewController;

左岸枫 2024-11-16 14:11:34

合成您的地图视图控制器。

Synthesize your map view controller.

远昼 2024-11-16 14:11:34

您必须在 Demo1AppDelegate.m 中添加 @synthesize mapViewController;

您还应该在 Demo1AppDelegate.m 的 dealloc 方法中添加 [mapViewController release]; (其中mapViewController是一个实例变量)。

You have to @synthesize mapViewController; in Demo1AppDelegate.m

You should also add [mapViewController release]; in the dealloc method of Demo1AppDelegate.m (with mapViewController being an instance variable).

如日中天 2024-11-16 14:11:34

添加委托如下...这可能是问题所在:
@interface Demo1AppDelegate : NSObject

Add delegate as follows ... This might be the issue :
@interface Demo1AppDelegate : NSObject <UIApplicationDelegate>

少年亿悲伤 2024-11-16 14:11:34

添加

@class MapViewController  

尝试在 Demo1AppDelegate.h 中的 @implementation Demo1AppDelegate 之前

Try adding

@class MapViewController  

before @implementation Demo1AppDelegate in Demo1AppDelegate.h

再浓的妆也掩不了殇 2024-11-16 14:11:34

嘿!在哪里添加子视图

[window addSubview:self.mapViewController.view]; [window makeKeyAndVisible];

尝试不使用“self”

[window addSubview:mapViewController.view]; [window makeKeyAndVisible];

只是一个猜测。

Hey! Where you add the subview

[window addSubview:self.mapViewController.view]; [window makeKeyAndVisible];

Try without "self"

[window addSubview:mapViewController.view]; [window makeKeyAndVisible];

Just a flying guess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文