在我的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