I'm dealing with some very weird issues by simply trying to pass a float parameter in obj-c.
I have a method which is called via an NSNotification:
- (void)presetChanged:(NSNotification*)notification {
float newValue = [[S76PresetManager sharedMana开发者_如何学编程ger] getValueForKey:symbol];
[self setValue:newValue animated:YES];
[PdBase sendFloat:newValue toReceiver:symbol];
}
When I run this through the debugger, a float (say 0.5) will remain the same and get sent to the [PdBase sendFloat:] line. However, in the [self setValue:animated:] call, I get a garbage value of 3.68934881e+19. This is very strange. Any suggestions?
Thanks in advance
EDIT: Nothing special was happening in [self setValue:animated:], just doing some bounds checking before sending it to another method...
- (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];
}
Assuming you aren't doing anything strange in [self setValue:newValue animated:YES]...
How about:
NSNumber *newValue = [NSNumber numberWithFloat:[[S76PresetManager sharedManager] getValueForKey:symbol]];
[self setValue:newValue animated:YES];
[PdBase sendFloat:[newValue floatValue] toReceiver:symbol];
精彩评论