views:

24

answers:

2

Hello All,

i Have some problem. i have 25 records in my NSMutableArray and i want to display them 5 records at a time when user press Next button then another 5 records to display and when user press back button then previous 5 records to display.

How can i do this any help from you would be great. Thank You.

A: 

Make an ivar in your table view controller that tracks which records you should display. Set the ivar in your Next/Back buttons action method and send [self.tableView reloadData]. Use the ivar in -tableView:numberOfRowsInSection: and -tableView:cellForRowAtIndexPath: to determine how many and which cells to display.

Costique
A: 

First of all, I recommend against this design. Tableviews on iPhone apps are great to scroll with your fingers, and having buttons like this defeats this. However, I don't know what you're doing, so I'll assume it's cool.

My suggestion is to use slices of the larger array as follows:

- (NSArray *)itemsForPage:(NSUInteger)p {
    NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(5*p,5)];
    return [_thatOneLargeArray objectsAtIndexes:indexes];
}

Note that I've refactored this code into a method. Let me know if this is helpful!

Jonathan Sterling