将数字列解析为 CGFloat

Parse Number Column to CGFloat

我遇到的问题是我使用的图像高度存储在 Parse class 列中,类型为数字。然后我使用该高度数字并使用它来设置 UITableview 行高。问题是,当我尝试使用数字列值时,它 returns 出现错误,指出类型不匹配。我在 Objective C 中这样做。如何使用数字值作为行高?我很确定我需要将 Number 值转换为 CGFloat,但我不确定。

NSNumber 已经为您提供了选项。

我建议您阅读找到的文档 here

苹果文档摘录:

NSNumber is a subclass of NSValue that offers a value as any C scalar (numeric) type. It defines a set of methods specifically for setting and accessing the value as a signed or unsigned char, short int, int, long int, long long int, float, or double or as a BOOL.

回答你的问题。

您可以使用 floatValue 从 NSNumber

中获取 CGFloat

示例:

CGFloat myFloat = [number floatValue];