我想访问一个整数和一个字符串从一个类到所有其他类?
最好的方法是什么?
我想在程序中的任何位置增加值,然后想要在声明的类中更新它们….
最好的方法是什么?
我想在程序中的任何位置增加值,然后想要在声明的类中更新它们….
任何想法如何实现这一点???
解决方法
关于
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]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。