I have an Array with content. as usual it contain 20 objects. I want the same array split into 2 sections in Tableview. I am trying to implement it with NSMake in current array. For example I need get in first tableview section 3 rows and second will contain all the rest (17 rows ).
switch (section) {
case 0:
return
[[array subarrayWithRange:NSMakeRange(3, 8)] count];
// in this line, it always takes from the first object in array, despite I told hime start from 3 (If I understand right, how to works NSMakeRange)
break;
case 1:
return
[[array subarrayWithRange:NSMakeRange(9, 19)] count];
// here my app is crashing with an error
//*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray subarrayWithRange:]: range {9, 19} extends beyond bounds [0 .. 19]'
default:
break;
}
Does anyone can help me with that?
NSRange
and a wastedNSArray
. – Neutralismlength
value of theNSRange
. – NeutralismI don't need to return count of array objects. section 1 should contain objects from 1 to 3 and section 2 should contain from 4 to 20.
I'm assuming, based on that, and the fact that he IS using subarrays that what he really wants is the objects. I'm guessing this is used in a tableview rows for various sections. If this is for the number of rows, you're right, he should just just use hardcoded counts. – ThroatyNSMakeRange
, why not just return that length directly? There is no point to creating a subarray just to return its count when you are hardcoding the length of the subarray. The hardcoded length and the resulting subarray count will always be equal. – Neutralism