Objective-C的 - 在另一个类中使用从一个类的布尔值 [英] objective-c - using a boolean value from one class in another class

查看:282
本文介绍了Objective-C的 - 在另一个类中使用从一个类的布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,但没有找到一个独特的回答这个问题。所以我问在这里。我有两个班。 ClassA和ClassB的。我在ClassB的一个布尔值。我有一个的ClassA方法,在那里寻找ClassB的这个值是真为了要断火法。我真的不知道怎么去ClassA的一看就知道价值。任何帮助将是巨大的。提前致谢!

I've looked around and couldn't find a distinct answer to this question. So I'm asking here. I have two classes. ClassA and ClassB. I have a bool value in ClassB. I have a method in ClassA where it is looking for that value in ClassB to be True in order for the method to fire off. I'm not really sure how to get ClassA to see that value. Any help would be great. Thanks in advance!

推荐答案

小心了全局定义。
如果你的类必须保存用户设置,你可以使用:
为节省:

be careful with the "global definition". if your class must save the user settings, you can use: for save:

 NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
 [pref setBool:YES forKey:@"AudioIsON"];
 [pref synchronize];

阅读:

BOOL myBooleanSetting = [[NSUserDefaults standardUserDefaults] boolForKey:@"AudioIsON"];

而不是,是更好地了解代表和属性。

instead of, is better to learn the delegate and the property.

希望这有助于你。

这篇关于Objective-C的 - 在另一个类中使用从一个类的布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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