Skip to content

Instantly share code, notes, and snippets.

@coneybeare
Created September 18, 2010 16:13
Show Gist options
  • Save coneybeare/585800 to your computer and use it in GitHub Desktop.
Save coneybeare/585800 to your computer and use it in GitHub Desktop.
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// FooDataSource.m
- (void)tableViewDidLoadModel:(UITableView*)tableView {
NSMutableArray* items = [[NSMutableArray alloc] init];
[self addTableItemsToArray:items]; // Implement yourself for your data
TTTableMoreButton *button = [TTTableMoreButton itemWithText:@"Loading More..."];
[items addObject:button];
}
- (void)tableView:(UITableView*)tableView cell:(UITableViewCell*)cell willAppearAtIndexPath:(NSIndexPath*)indexPath {
[super tableView:tableView cell:cell willAppearAtIndexPath:indexPath];
if (indexPath.row == self.items.count-1 && [cell isKindOfClass:[TTTableMoreButtonCell class]]) {
TTTableMoreButton* moreLink = [(TTTableMoreButtonCell *)cell object];
moreLink.isLoading = YES;
[(TTTableMoreButtonCell *)cell setAnimating:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.model load:TTURLRequestCachePolicyDefault more:YES];
}
}
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// FooTTURLRequestModel.h
@interface UARecentRecallsModel : TTURLRequestModel {
NSMutableArray * _objects;
NSInteger _page;
}
@property (nonatomic, retain) NSMutableArray *objects;
@property (nonatomic, assign) NSInteger page;
@end
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// FooTTURLRequestModel.m
@implementation UARecentRecallsModel
@synthesize objects = _objects;
@synthesize page = _page;
- (id) init {
self = [super init];
if (self != nil) {
self.objects = [NSMutableArray array];
}
return self;
}
- (void) dealloc {
TT_RELEASE_SAFELY(_objects);
[super dealloc];
}
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
if (!self.isLoading) {
if (more) {
self.page += 1;
} else {
[self.objects removeAllObjects];
self.page = 1;
}
[self makeRequestForData]; // Implement yourself for your data
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)requestDidFinishLoad:(TTURLRequest*)request {
NSMutableArray* objects = [self parseRequestIntoObjects]; // Implement yourself for your data
[self.objects addObjectsFromArray:objects];
TT_RELEASE_SAFELY(objects);
[super requestDidFinishLoad:request];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment