在我的AppDelegate我有这样一个NSObject的一个参考:UIApplicationDelegate问题
@interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
MyObjectManager * myObjectManager;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) MyObjectManager * myObjectManager;
我想从我的UIViewController访问此,所以我这样做:
MyAppDelegate * appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
MyObjectManager * myObjectManager = appDelegate.myObjectManager;
maMyArray = [[NSMutableArray alloc] init];
[[appDelegate myObjectManager] findMyStuff:5 foundArray:maMyArray];
//[myObjectManager findMyStuff:5 foundArray:maMyArray];
不过,我觉得我不正确理解Objective C中的语法,因为我引发了异常EXC_BAD_ACCESS。当我看着这些价值观时,他们看起来是正确的。
有人能解释我做错了什么吗?
感谢
我是的,在MyAppDelegate中。我这样做:MyObjectManager = [[MyObjectManager alloc] initWithContentsOfSQLiteDB:@“MyDB.sql”];我还需要做些别的吗? – LilMoke 2011-05-16 20:45:41
哦,我明白了,好的,但是我在哪里可以调用init来做我需要做的事情?我可以在我的init函数中调用[[self alloc] init]吗? – LilMoke 2011-05-16 20:47:55
只要那是myObjectManager =,而不是MyObjectManager =,你的代码也应该正常工作。如果你在findMyStuff:方法调用之前放置一个断点,myObjectManager指向什么? – Joe 2011-05-16 20:52:28