我的問題是「R real:」的結果是完美的,但是當我將例如'cloth.R'轉換爲int時,結果爲0.我該如何解決這個問題。 謝謝。爲什麼我的NSString int在Objective C中是錯誤的?
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'對象嗎? – trojanfoe
...如果是,並且用於保存R,G,B值,那麼*爲什麼*它是一個'NSString'對象而不是'int'? – trojanfoe
爲什麼你將R,G,B作爲NSString存儲在布料中? 使用CGFloat。 或更好具有UIColor屬性。 –