Aviad Ben Dov and rkbang offer some useful advice. Adding to that:
To respond to a touch on your "View More" cell, write a tableView:willSelectRowAtIndexPath:
method (from the UITableViewDelegate
protocol) in whichever object is the delegate for your UITableView
. In this method, make a call to load more data, and return nil
so the row does not stay selected (which is more button-like behavior):
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self loadMoreData];
return nil; // Don't leave this row selected.
}
In your load function, make a server call to get the data, parse it, and reload the table. It's also polite to give a busy indicator while you're waiting for the server reply:
#import "HTTPHelper.h"
// ... later ...
- (void) loadMoreData {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
NSString* dataStr = nil;
NSError* error = [[HTTPHelper sharedInstance]
synchronousGetURLAsString:@"http://server.com/mystuff"
replyData:&dataStr];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error) {
[self displayErrorMessage:error];
} else {
[self parseIntoDataSource:dataStr];
[tableView reloadData];
}
}
In this last function, I'm assuming the method parseIntoDataSource
will parse the server reply and add that data to whatever your class uses to provide the data for table cells which are given by the tableView:cellForRowAtIndexPath:
method (of the UITableViewDataSource
protocol).
That code also uses HTTPHelper
from the moriarty library.
If you want to parse XML, you can use the SDK's own NSXMLParser
. The TouchXML library is also available, and offers a little more robust support for slightly dirty data (like real-world html, which does not usually conform to XML standards). To parse JSON, you could use the json-framework, which has a very simple category-based interface.