Iphone从AppDelegate访问属性值 [英] Iphone access a property value from AppDelegate
问题描述
如何从someView控制器访问AppDelegate类的属性值而不在视图控制器中创建委托的引用?
How to access a property value of AppDelegate class from someView Controller without creating reference of the delegate in view controller?
推荐答案
我不太清楚你的意思 - 有多种方法可以将你的应用程序委托中的信息传递给视图控制器,并且不创建委托的引用这一短语不清楚。您的选择基本上是:
I'm not quite sure what you mean - there are multiple ways to get information from your application delegate into a view controller, and the phrase "without creating reference of the delegate" is unclear. Your options basically are:
- 引用应用程序委托,并根据需要进行转换。您可以在视图控制器类中编写代码,如:
- Reference the application delegate, casting as appropriate. You would write code in your view controller class like:
id propertyValue = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] myProperty];
@property
并使用 @synthesize
d,然后你就可以拥有该应用程序delegate只是在视图控制器实例上设置属性。
@property
declared and @synthesize
d for use, then you would have the app delegate just set the property on the view controller instance.这两个选项都不要求您保留应用程序代理的副本作为 @property
,但第一个确实引用了一次委托。
Neither of these options require that you retain a copy of your app's delegate as a @property
, but the first does reference the delegate once.
这篇关于Iphone从AppDelegate访问属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!