1

在 Objective-C 中,我想在 Class from Class中设置一个synthesized (assigned)属性CompassB

这是我的代码...

for(Compass * ind in CompassList){  
    if([[(Compass*)ind showAnalog] isEqualToString:str]){  
        ind.analogValue=11.0;  
    }  
}

但是,我收到此错误...

Request for member analogValue in something not a structure or union.

我设法通过使用我自己的设置器并将其称为[ind updateValue:11.0];. 但是,当我稍后像在另一个类中调用合成的 getter 时[(Compass*)currentDevice analogValue];,我得到以下异常......

'NSInvalidArgumentException': [Compass digitalValue]: unrecognized selector sent to instance 0x613ca20

有人可以帮我理解我应该如何做到这一点。

4

1 回答 1

0

您正在快速将 indicatorList 枚举为类型,Indicator然后将其下方的一行转换为Compass. 如果这不是拼写错误并且所有值都是类型,Compass则将代码更改为读取

for(Compass * compass in indicatorList){  
    if([[compass showAnalog] isEqualToString:str]){  
        compass.analogValue=11.0;  
    }  
}

现在对于您的实际问题,您没有发布与该问题相关的代码。我猜原因是来自一些showAnalog正在调用的代码,而这些代码又会调用[(Compass*)currentDevice analogValue];. 这可能都与不正确的转换或未完全实现Compass该类有关。

于 2011-03-30T21:08:51.243 回答