【发布时间】:2013-07-21 10:43:03
【问题描述】:
我的问题是“R real:”的结果是完美的,但是当我将例如 'cloth.R' 转换为 int 时,结果为 0。我该如何解决它。 谢谢。
Cloth *cloth = [app.clothArray objectAtIndex:0];
NSLog(@"R real:%@",cloth.R);
NSLog(@"G real:%@",cloth.G);
NSLog(@"B real:%@",cloth.B);
NSString *aNumberString = cloth.R;
int i = [aNumberString intValue];
NSLog(@"NSString:%@",aNumberString);
NSLog(@"Int:%i",i);
结果:
2013-07-22 18:57:45.965 App_ermenegild[26030:c07] R real:
232
2013-07-22 18:57:45.965 App_ermenegild[26030:c07] G real:
0
2013-07-22 18:57:45.965 App_ermenegild[26030:c07] B real:
121
2013-07-22 18:57:45.966 App_ermenegild[26030:c07] NSString:
232
2013-07-22 18:57:45.966 App_ermenegild[26030:c07] Int:0
编辑
这里是Cloth类
@interface Cloth : NSObject
@property(nonatomic,retain) NSString *nom;
@property(nonatomic,retain) NSString *R;
@property(nonatomic,retain) NSString *G;
@property(nonatomic,retain) NSString *B;
@property(nonatomic,retain) NSString *col;
@property (nonatomic,readwrite) NSInteger *clothID;
@end
这里是 XML 文件模式:
<cloth id="1">
<nom>Heliconia</nom>
<R>232</R>
<G>0</G>
<B>121</B>
<col>#E80079</col>
</cloth>
【问题讨论】:
-
cloth.R绝对是NSString对象吗? -
... 如果是,并且用于保存 R、G、B 值,那么 为什么 它是
NSString对象而不是int? -
为什么要将 Cloth 中的 R、G、B 存储为 NSString ?使用 CGFloat。或者更好的是有 UIColor 属性。
-
我想不出一些会导致上述症状的场景。您需要向我们展示 Cloth 的定义,以及如何设置 R/G/B 值。
-
您确定这是您正在运行的确切代码吗?您没有遗漏或重新输入任何内容吗?运行此代码时,我得到了正确的结果。
标签: objective-c nsstring int