AppDelegate抱怨由于未捕获的异常而终止应用程序

时间:2013-10-02 11:43:23

标签: iphone ios objective-c appdelegate

我正在尝试从AppDelegate读取和写入值。我最终有一个例外

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate myViewDelegate]: unrecognized selector sent to instance 0xc07a9b0'

APPDelegate.h

@interface AppDelegate : NSObject <UIApplicationDelegate> {
    MyView *myViewDelegate;
}
@property (nonatomic,strong) MyView *myViewDelegate;
APPDelegate.m

中的

- (void) _application:(UIApplication *)application commonInitializationLaunching:(NSDictionary *)launchOptions{
...
    self.myViewDelegate = [[MyView alloc] init];

}

MyView.h   我有NSDate *d;

@property(nonatomic,strong) NSDate *d;
@synthesis d;

MyView.m


PaymentView.m

- (void) loadView{
    [super loadView];
     AppDelegate *del=(AppDelegate *)[[UIApplication sharedApplication] delegate];
     del.myViewDelegate.d = myDate;// myDate is a NSDate
}

2 个答案:

答案 0 :(得分:0)

假设您没有使用最新Xcode的自动@synthesize,请将此添加到AppDelegate.m

@synthesize myViewDelegate;

同样删除 - 如果您有属性+综合,则不需要:

MyView *myViewDelegate;

答案 1 :(得分:0)

通常AppDelegate的父类是UIResponder ..所以我的猜测是,当你打电话给它时,

 AppDelegate *del=(AppDelegate *)[[UIApplication sharedApplication] delegate];

你要回来的代表不是你的类......当你试图在返回的对象上调用myViewDelegate时,它没有该属性。在源代码中找到main.m类,并看到你的AppDelegate类传递类似于下面的行

 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

如果该AppDelegate类实际上是您的类,并且当您cmd +单击类名时,它将带您到该类源。