I have like 100 records to display on a table. But i will be only displaying 10 records, and when the user clicks the last row (Which will have a button that will say load the next 10 records) the table will row the next 10 records.
I have displayed the more button on the last cell successfully. But i don’t know how to display 10 records at a time. My code so far;
ViewDidLoad
self.arrayThatContainsAllHundredRecords= [NSArray arrayWithArray:hundredRecordsArray];
[self performSelector:@selector(addTheTableFooter:) withObject:nil afterDelay:0.5];
addTheTableFooter
UIView* footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[footer addSubview:moreButton]; // i have also added an event to the button click see below, and i have not shown it here.
self.tableView.tableFooterView =footer;
[self.mainWindow removeFromSuperview];
[self.tableView reloadData];
The above would Display the More button after displaying all 100 records.
moreButtonClickAction
-(void)moreButtonClickAction {
NSLog(@"Suppose to load the next 10 records");
}
numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.arrayThatContainsAllHundredRecords count];
}
I need a way to edit this code, so i will only display 10 records at a time, and display the next 10 when the user clicks the more button. (Now the total records should be 20 – (previous 10 + the 10 records as a result of clicking the more button ))
NOTE: I will be downloading all 100 records and saving it in self.arrayThatContainsAllHundredRecords in the viewDidLoad method.
I believe that i have to make some change before executing [self.tableView reloadData];, as in tell to load 10 records.
Well, say if i only had 53 records. Then the user will click the more button 5 times and on the 6th instance, the table should display only 3 records. How can this be handled in the tableview:numberOfRowsInSection: ?
tableView:numberOfRowsInSection:is the method that determines how many rows will be shown, so the first step will be to change that. You also need a property in your view controller to keep track of how many rows should be visible. Something like this:And when the more button is clicked, you have to increase that number and reload the tableView data.