I’m trying to convert a sectionned table into a flat list using this function into didSelectRowAtIndexPath (I have a NSArray that is initialisated with the number of items contained in each section) :
Somewhere… 🙂
self.sectionsArray = [NSArray arrayWithObjects:macroIntNumber(1), macroIntNumber(3), macroIntNumber(12), nil];
then into 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;
But… This crashes for indexPath.section = 0 (first section).
Because the loop is played infinitly until crash of the NSArray call…
Strange !!!
forcing for (int i=0; i<0-1; i++) { works
forcing for (int i=0; i<a-1; i++) { works
What am I missing ?
sectionis anNSUInteger, so it’s unsigned. Thus, subtracting 1 from 0 on that unsigned integer is taking you to a very large number rather than -1.It works when using
a, because you’ve declaredaas anint. 🙂