解决方法
关于
singletons,这是一个问题(和好的答案).
您也可以像frankodwyer建议的那样使用app delegate,并使用以下方式从任何地方访问它:
id delegate = [[UIApplication sharedApplication] delegate];
为了便于使用和类型安全,我使用这样的类别:
// put his in your delegate header file @interface UIApplication(MyAppAdditions) + (MyAppDelegate*)sharedDelegate; @end // put his in your delegate implementation file @implementation UIApplication(MyAppAdditions) + (MyAppDelegate*)sharedDelegate { return (MyAppDelegate*)[[self sharedApplication] delegate]; } @end
现在,您可以从任何地方访问您的应用程序代理:[UIApplication sharedDelegate]