如何从另一个访问viewcontroller的属性?苹果手机 [英] How to access a property of a viewcontroller from another one? iPhone

查看:106
本文介绍了如何从另一个访问viewcontroller的属性?苹果手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在viewcontroller中定义了一个属性A

I define a property in the viewcontroller A

  @property (nonatomic) BOOL updateOnServer;

并合成它,给它值,然后我尝试从另一个viewcontroller B访问这个变量这个

and also synthesize it, give it values and then I try to access this variable from another viewcontroller B like this

  A * view = [[A alloc] init];

  if (view.updateOnServer)

但它不起作用。 updateOnServer始终为NO。

but it isn't working. updateOnServer is always NO.

有没有人知道如何解决这个问题?

Does anybody have an idea on how to solve this?

推荐答案

在viewControllerA中设置 updateOnServer ,在viewControllerB中创建一个 updateOnServer 的新实例没有任何设定。因此它需要BOOL的默认值为NO。

You set updateOnServer within viewControllerA, and in viewControllerB you create a new instance of updateOnServer which you haven't set to anything. So it takes the default value of BOOL which is NO.

请看这里可能的解决方案。

你有很多方法可以做:将变量设为全局,静态,singleton,作为参数传递,作为通知发布。

You have many ways to do : make the variable global, static, singleton, pass as an argument, post as notification.

这篇关于如何从另一个访问viewcontroller的属性?苹果手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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