NSMakeRange
is defined as (startingIndex, length)
, not (start, end)
which it seems like how you are trying to use it.
So if you need the first 3 objects, then the rest it would look like this:
switch (section) {
case 0:
// This returns objects 0-2 in the array
return [array subarrayWithRange:NSMakeRange(0, 3)];
case 1:
// This returns objects 3-20 in the array
return [array subarrayWithRange:NSMakeRange(3, 17)];
default:
break;
}
Edit: According to your comment, you are actually looking for the count to return in number of rows in section. Since you are using a fixed number of rows, you can just return the actual number within the case statement.
switch (section) {
case 0:
// This returns the count for objects 0-2 in the array
return 3;
case 1:
// This returns the count for objects 3-20 in the array
return 17;
default:
break;
}
You do not actually need to use [subarrayWithRange]
, nor NSMakeRange
. If you do need to at some point reference the actual array, you will get an NSIndexPath object which you can use to get the object from your array. You will need to use the section and row properties.
Edit: NSRange
-> NSMakeRange