iphone - 传递 float 给出垃圾值

标签 iphone objective-c ios

我通过简单地尝试在 obj-c 中传递一个浮点参数来处理一些非常奇怪的问题。

我有一个通过 NSNotification 调用的方法:

    - (void)presetChanged:(NSNotification*)notification {

float newValue = [[S76PresetManager sharedManager] getValueForKey:symbol];

[self setValue:newValue animated:YES];
[PdBase sendFloat:newValue toReceiver:symbol];
}

当我通过调试器运行此命令时, float (例如 0.5)将保持不变并被发送到 [PdBase sendFloat:] 行。然而,在 [self setValue:animated:] 调用中,我得到一个垃圾值 3.68934881e+19。这很奇怪。有什么建议吗?

提前致谢

编辑:[self setValue:animated:] 中没有发生什么特别的事情,只是在将其发送到另一个方法之前进行一些边界检查...

    - (void)setValue:(float)newValue animated:(BOOL)animated {
float oldValue = value;

if (newValue < 0.0)
    value = 0.0;
else if (newValue > maxValue)
    value = maxValue;
else
    value = newValue;

[self valueDidChangeFrom:oldValue to:value animated:animated];
    }

最佳答案

假设你在 [self setValue:newValueanimated:YES] 中没有做任何奇怪的事情...

怎么样:

NSNumber *newValue = [NSNumber numberWithFloat:[[S76PresetManager sharedManager] getValueForKey:symbol]];

[self setValue:newValue animated:YES];
[PdBase sendFloat:[newValue floatValue] toReceiver:symbol];

关于iphone - 传递 float 给出垃圾值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7249527/

相关文章:

ios - NSDateFormatter 缺少方法...我是否缺少导入

ios - 检测换行符在 UI​​TextView 中开始的时刻

iphone - Core Data 中多语言数据的良好实践

iphone - 在 iOS 中实现表单的最佳实践是什么

ios - 可重用的 TableViewCell 加载旧图像

ios - 双维标签计数

ios - 主事件循环和应用程序的运行循环有什么区别?

ios - 基于核心数据对象,仅选择带有复选标记的一行

iphone - bundle 和文件访问

iphone - 收到 "A valid signing identity matching this profile could not be found in your keychain"警告