在我的AppDelegate中有一个对NSObject的引用,如下所示:
@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。当我查看这些值时,它们似乎是正确的。
有人能解释一下我做错了什么吗?
谢谢
发布于 2011-05-17 04:43:19
您必须在以下位置初始化myObjectManager:
myObjectManager = [[MyObjectManager alloc] init];最好的地方可能是- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法。
别忘了在dealloc中释放它。
发布于 2011-05-17 04:42:39
分配MyObjectManager并将其分配给myObjectManager属性的代码在哪里?
在你做到这一点之前,它是零。
https://stackoverflow.com/questions/6023073
复制相似问题