我有一个 NSSlider,它正在尝试将常规 float 转换为 CGFloat。我正在使用的代码:
CGFloat testing = [mainSlider floatValue];
但是,当我尝试记录它时,这只会使测试变量“0.00”。
NSLog(@"%f", testing);
有人知道为什么会发生这种情况吗?感谢您的帮助。
最佳答案
- 检查 mainSlider 是否为 nil
尝试一下以防万一(不记得 CGFloat 是否为 double ):NSLog(@"%f", (double)testing);
检查变量是否没有像这样被隐藏:
CGFloat testing = 0.0; if(YES){ CGFloat testing = [mainSlider floatValue]; //should be: testing = [mainSlider floatValue]; } NSLog(@"testing = %f", testing); //this will print "testing = 0.000000"
关于cocoa - CGFloat 的 floatValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1225564/