我有下面。nsmutablearray.count和tableview indexpath.row之間的比較給出了奇怪的結果
NSLog(@"aaaa===%ld==%ld", indexPath.row, (rowsOptionss.count-1));
if (indexPath.row>(rowsOptionss.count-1)) {
NSLog(@"000===this is true");
} else {
NSLog(@"000===this is false");
}
if (0>-1) {
NSLog(@"001===this is true");
} else {
NSLog(@"001===this is false");
}
這是給我下面的結果。
2016-02-04 13:02:15.316 ClubsFans[7085:16944474] aaaa===0==-1
2016-02-04 13:02:15.316 ClubsFans[7085:16944474] 000===this is false
2016-02-04 13:02:15.316 ClubsFans[7085:16944474] 001===this is true
我預計說
2016-02-04 13:02:15.316 ClubsFans[7085:16944474] aaaa===0==-1
2016-02-04 13:02:15.316 ClubsFans[7085:16944474] 000===this is true >> this should be true
2016-02-04 13:02:15.316 ClubsFans[7085:16944474] 001===this is true
知道爲什麼這是怎麼了?
無符號整數下溢。使用無符號整數時,添加比減去例如總是更安全。 'indexPath.row + 1
Sulthan