0

我正在尝试从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
}
4

2 回答 2

0

通常 AppDelegate 的父类是 UIResponder.. 所以我的猜测是当你调用它时,

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

您要返回的委托不是您的班级......当您尝试在返回的对象上调用 myViewDelegate 时,它​​没有该属性。在你的源代码中找到 main.m 类,并看到你的 AppDelegate 类被传入类似于下面的行

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

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

于 2013-10-02T13:02:28.827 回答
0

假设您没有使用最新 Xcode 中的 auto @synthesize,请将其添加到 AppDelegate.m

@synthesize myViewDelegate;

还要删除它-如果您有属性+合成,则不需要:

MyView *myViewDelegate;
于 2013-10-02T11:49:32.830 回答