我的问题是“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>