Iphone从AppDelegate访问属性值 [英] Iphone access a property value from AppDelegate

查看:84
本文介绍了Iphone从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:


  1. 引用应用程序委托,并根据需要进行转换。您可以在视图控制器类中编写代码,如:
  1. 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只是在视图控制器实例上设置属性。

  • Pass the property in when creating the view controller. This requires the view controller to have a @property declared and @synthesized 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆