Sudha Tiwari Sudha Tiwari - 1 year ago 87
Objective-C Question

load earlier messages concept in tableview

enter image description here

I was trying to add the load earlier messages concept same as Whats app. But it is inserting the rows from the bottom of the table instead of the top.

#define kNumberOfItemsToAdd 20

NSUInteger i, totalNumberOfItems = [messageArray count];
newNumberOfItemsToDisplay = MIN(totalNumberOfItems, numberOfItemsToDisplay + kNumberOfItemsToAdd);
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
for (i=numberOfItemsToDisplay; i<newNumberOfItemsToDisplay; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
numberOfItemsToDisplay = newNumberOfItemsToDisplay;
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView endUpdates];

Anybody has idea that how to load content from top?

Answer Source

Change your index paths so that they range from zero to newNumberOfItems-numberOfItemsToDisplay.

You'll also need to fetch the right elements in your data source so that the items in the new range are indeed the older messages.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download