I need to display 6 views and each view should display 20 items (UIButtons). I have one big NSArray which contains the items for all 6 views.
For example, view 1 should be items 0-19, view 2 should be items 20-39.
How would i extract the relevant range out of the array? Maybe using NSRange with a length of 20, but the start location would need to change for each view... without a switch statement ideally :)
Thanks
static const NSUInteger ItemsPerView = 20;
NSUInteger startIndex = viewIndex * ItemsPerView;
NSUInteger count = MIN( completeArray.count - startIndex, ItemsPerView );
NSArray *itemsForView = [completeArray subarrayWithRange: NSMakeRange( startIndex, count )];
Your answer is in your question. Just keep track of which NSRange belongs to which view and use it to look up the necessary objects in your container using NSArray's -subarrayWithRange: method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With