(rowsOptio-6ren">
gpt4 book ai didi

ios - nsmutablearray.count和tableview indexpath.row之间的比较给出了奇怪的结果

转载 作者:行者123 更新时间:2023-12-01 17:49:35 25 4
gpt4 key购买 nike

我有下面。

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

知道为什么会出错吗?

最佳答案

这可以帮助您了解:

NSIndexPath* indexPath = nil;
NSArray * rowsOptionss = [NSArray array];
NSLog(@"aaaa===%ld==%ld", indexPath.row, (rowsOptionss.count-1));
NSLog(@"real value: bbbb===%ld==%u", (long)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");
}
rowsOptionss.count是无符号的 (NSUInteger),如果执行 -1操作,您将获得非常大的正数,该数字始终大于0。

那是日志:
 aaaa===0==-1
real value: bbbb===0==4294967295
000===this is false
001===this is true

如果您需要带符号的int,请改用以下方法:
NSInteger tempInt = rowsOptionss.count;
tempInt --;
LOG(@"tempInt %i", tempInt);

关于ios - nsmutablearray.count和tableview indexpath.row之间的比较给出了奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35197943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com