You can manullay handle the condition based on your number of records in Array. Here is I am giving you some sample code which would help you achieve what you want to do :
Here manage to return the number of rowns in cells, based on your records in Array.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ( [jsonArray count] < 20 ) //20 Will change based on your number of records as loop progresses.
{
return [self.localJsonArray count];
} else {
return [self.localJsonArray count] + 1;
}
}
Fill the data in cells, from Array and check for condition
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
ImageCell *cell = (ImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (indexPath.row != [localJsonArray count] ) { // As long as we haven’t reached the +1 yet in the count, we populate the cell like normal
if (cell == nil) {
cell = [[[ImageCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary *itemAtIndex = (NSDictionary *)[self.localJsonArray objectAtIndex:indexPath.row];
[cell setData:itemAtIndex];
} // Ok, all done for filling the normal cells, next we probaply reach the +1 index, which doesn’t contain anything yet
if ( [jsonArray count] == 20 ) { // Only call this if the array count is 25
if(indexPath.row == [localJsonArray count] ) { // Here we check if we reached the end of the index, so the +1 row
if (cell == nil) {
cell = [[[ImageCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Reset previous content of the cell, I have these defined in a UITableCell subclass, change them where needed
cell.cellBackground.image = nil;
cell.titleLabel.text = nil;
// Here we create the ‘Load More Posts.’ cell
loadMore =[[UILabel alloc]initWithFrame: CGRectMake(0,0,362,73)];
loadMore.textColor = [UIColor blackColor];
loadMore.highlightedTextColor = [UIColor darkGrayColor];
loadMore.backgroundColor = [UIColor clearColor];
loadMore.font=[UIFont fontWithName:@"Verdana" size:20];
loadMore.textAlignment=UITextAlignmentCenter;
loadMore.font=[UIFont boldSystemFontOfSize:20];
loadMore.text=@"Load More Posts...";
[cell addSubview:loadMore];
}
}
return cell;
}
And Lastly, maintain the event handling and differentiate between additional ROW with others :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ( [jsonArray count] == 20 ) { // Only call the function if we have 20 results in the array OR maintain its counts based on your array counts.
if (indexPath.row == [localJsonArray count] ) {
NSLog(@"Load More requested"); // Add a function here to add more data to your array and reload the content
} else {
NSLog(@"Normal cell selected"); // Add here your normal didSelectRowAtIndexPath code
}
} else {
NSLog(@"Normal cell selected with < 20 results"); // Add here your normal didSelectRowAtIndexPath code
}
}