【问题标题】:Properties on a Class Not Changing类的属性没有改变
【发布时间】:2013-06-20 15:43:28
【问题描述】:

好的,我有 2 节课。

一个包含所有属性,一个包含所有方法。

在我称之为的所有方法的类中。

    switch (_allProperties.switchNumber) {
    case 0:
        CCLOG(@"Saving Info");
        CCLOG(@"FirstNumber = %d",numberA);
        CCLOG(@"SecondNumber = %d",numberB);
        //I get the correct numbers on the dbg
        _allProperties.firstNumber = numberA;
        _allProperties.secondNumber = numberB;

        CCLOG(@"Properties.FirstNumber = %d",_allProperties.firstNumber);
        CCLOG(@"Properties.SecondNumber = %d",_allProperties.secondNumber);
        //Im getting 0 on both of this logs.
        break;

所以,这就是我在 allMethods 类上调用 _allProperties 的方式

           @property (strong) PropertiesClass *allProperties;

下面是 .FirstNumber && .SecondNumber 如何在 PropertiesClass 上强制转换

         @property (nonatomic, assign) int firstNumber;
         @property (nonatomic,assign) int secondNumber;

我错过了什么?为什么属性没有获得价值??

感谢您的宝贵时间,祝大家有美好的一天!

【问题讨论】:

    标签: cocoa-touch cocos2d-iphone xcode4.5


    【解决方案1】:

    现在我明白了,你仍然声明了 PropertiesClass 的属性并且不分配和初始化这个类。 在使用 _allProperties 之前,您应该通过以下方式分配和初始化它:_allProperties = [[PropertiesClass alloc]init];

    【讨论】:

    • 我做了:_allProperties = [[PropertiesClass alloc] init];在 allMethods 的 init 方法中,没关系,我还在我进行切换的方法上对其进行了初始化,并且它起作用了。 :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多