xcodeのcomponentsSeparatedByString関数を使用して文字列を配列に分離しているときに、この問題が発生します。
だから私はこの文字列から配列を作成します:
theDataObject.stringstick = @"1 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0";
stickerarray = [[NSMutableArray alloc] initWithArray:[theDataObject.stringstick componentsSeparatedByString:@" "]];
だから私の心の中で私は期待しています:
stickerarray = {@"1",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"1",@"0",@"1",@"1",@"1",@"0",@"0",@"0"}
したがって、ifステートメントを介してそれをチャックしてインデックスが=1であるかどうかを確認するとき
for ( int n = 0; n <= 15; n++) {
if ([stickerarray objectAtIndex:n] == @"1") {
NSLog(@"this works %i", n);
} else {
NSLog(@"this did not work on %@", [stickerarray objectAtIndex:n]);
}
}
これは私が得るものです:
this did not work on 1
this did not work on 0
this did not work on 0
this did not work on 0
this did not work on 0
this did not work on 0
this did not work on 0
this did not work on 0
this did not work on 1
this did not work on 0
this did not work on 1
this did not work on 1
this did not work on 1
this did not work on 0
this did not work on 0
this did not work on 0
これが機能しないことに驚いたので、いくつかのクエリを適用してみました。
NSLog(@"ns array value of %@",[stickerarray objectAtIndex:2] );
ns array value of 0
NSLog(@"%@", stickerarray);
(
1,
0,
0,
0,
0,
0,
0,
0,
1,
0,
1,
1,
1,
0,
0,
0
)。
NSLog(@"%@", theDataObject.stringstick);
1 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0
ifステートメント内で比較すると、@"1"だと思います。あなたが私のためにこれを修正することができれば、大きな助けになります。ありがとう :)