我正在尝试使用此函数将分区表转换为平面列表到didSelectRowAtIndexPath(我有一个NSArray初始化为每个节中包含的项目数):
某处... :-)
self.sectionsArray = [NSArray arrayWithObjects:macroIntNumber(1), macroIntNumber(3), macroIntNumber(12), nil];
然后进入didSelectRowAtIndexPath:
int selectedRow = 0;
int a = indexPath.section;
for (int i=0; i<indexPath.section-1; i++) {
selectedRow += [[self.sectionsArray objectAtIndex:i] intValue];
}
selectedRow += indexPath.row;
但是...对于indexPath.section = 0(第一部分),这将崩溃。
因为循环会无限循环播放直到NSArray调用崩溃...
奇怪!
强制
for (int i=0; i<0-1; i++) {
工作强制
for (int i=0; i<a-1; i++) {
工作我想念什么?
最佳答案
section
是NSUInteger
,因此未签名。因此,从该无符号整数的0中减去1将使您获得一个非常大的数字,而不是-1。
使用a
时可以使用,因为您已将a
声明为int
。 :)
关于objective-c - Objective-C-循环播放但循环条件为假,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4700608/