【发布时间】:2015-01-03 13:35:03
【问题描述】:
我有这个代码:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
NSLog([NSString stringWithFormat:@"\n%g pixel \n=======================================",screenWidth]);
CGFloat imageWidth = [[self.widthArray objectAtIndex:indexPath.row] floatValue];
NSLog([NSString stringWithFormat:@"\n%f pixel\n=======================================",imageWidth]);
CGFloat ratio = screenWidth / imageWidth;
NSLog([NSString stringWithFormat:@"\nratio is %f\n=======================================",ratio]);
screenWidth 和 imageWidth 完全没问题,但是当我尝试记录 ratio 时,程序会崩溃并且日志显示 (lldb)。我还没有在任何地方找到解决方案。有什么建议吗?
编辑:
前两个日志是
2015-01-03 08:49:00.888 Huckleberry[6554:158359]
320.000000 pixel
=======================================
2015-01-03 08:49:00.889 Huckleberry[6554:158359]
512.000000 pixel
=======================================
然后ratio 就是(lldb)
【问题讨论】:
-
1.价值观是什么? 2.研究
NSLog(),没必要用stringWithFormat。例如:NSLog(@"\n%g pixel\n=======================================", screenWidth); -
研究
NSLog(),没必要用stringWithFormat。例如:NSLog(@"\n%g pixel\n=======================================", screenWidth);。此外,NSLog()的格式字符串应该是文字,Xcode 甚至会对此发出警告。 -
对于 32 位平台
CGFLoat定义为float,对于 64 位平台CGFLoat定义为double。 -
它是崩溃还是你只是在那行有一个断点?
标签: objective-c operators cgfloat