mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-04 17:49:56 +08:00
* Introduces RKRequestCache for cacheing responses (supports ETag conditional GET, use cache if available, use cache on error, etc.) closes #75 * Updates to Three20 layer to eliminate need for intermediary TTTableItem classes closes #76 * Fixes to ensure iOS 3.x compatability: * Switched compiler to Clang * Updated conditional checks for UIBackgroundTask symbols to ensure runtime safety on iOS 3.x * Removed unnecessary linkage against UIKit and CoreFoundation from library targets * Fix for issue where RKRequest objects could become stuck in infinite loop within RKRequestQueue loadNextInQueue if you start a request and then cancel immediately. On cancel only decrement loadCount if the request has start loading. refs #122
85 lines
2.3 KiB
Objective-C
85 lines
2.3 KiB
Objective-C
//
|
|
// RKTableViewDataSource.m
|
|
// RestKit
|
|
//
|
|
// Created by Blake Watters on 4/26/11.
|
|
// Copyright 2011 Two Toasters. All rights reserved.
|
|
//
|
|
|
|
#import "RKTableViewDataSource.h"
|
|
#import "RKMappableObjectTableItem.h"
|
|
#import "RKObjectLoaderTTModel.h"
|
|
|
|
@implementation RKTableViewDataSource
|
|
|
|
+ (id)dataSource {
|
|
return [[self new] autorelease];
|
|
}
|
|
|
|
- (id)init {
|
|
self = [super init];
|
|
if (self) {
|
|
_objectToTableCellMappings = [NSMutableDictionary new];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)setModel:(id<TTModel>)model {
|
|
if (NO == [model isKindOfClass:[RKObjectLoaderTTModel class]]) {
|
|
[NSException raise:nil format:@"RKTableViewDataSource is designed to work with RestKit TTModel implementations only"];
|
|
}
|
|
|
|
[super setModel:model];
|
|
}
|
|
|
|
- (void)dealloc {
|
|
[_objectToTableCellMappings release];
|
|
|
|
[super dealloc];
|
|
}
|
|
|
|
- (NSArray*)modelObjects {
|
|
return [(RKObjectLoaderTTModel*)self.model objects];
|
|
}
|
|
|
|
- (void)registerCellClass:(Class)cellCell forObjectClass:(Class)objectClass {
|
|
[_objectToTableCellMappings setObject:cellCell forKey:objectClass];
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return [self.modelObjects count];
|
|
}
|
|
|
|
- (Class)tableView:(UITableView*)tableView cellClassForObject:(id)object {
|
|
RKMappableObjectTableItem* tableItem = (RKMappableObjectTableItem*)object;
|
|
Class cellClass = [_objectToTableCellMappings objectForKey:[tableItem.object class]];
|
|
NSAssert(cellClass != nil, @"Must have a registered cell class for type");
|
|
return cellClass;
|
|
}
|
|
|
|
- (id)tableView:(UITableView*)tableView objectForRowAtIndexPath:(NSIndexPath*)indexPath {
|
|
if (indexPath.row < [self.modelObjects count]) {
|
|
NSObject<RKObjectMappable>* mappableObject = [self.modelObjects objectAtIndex:indexPath.row];
|
|
RKMappableObjectTableItem* tableItem = [RKMappableObjectTableItem itemWithObject:mappableObject];
|
|
return tableItem;
|
|
} else {
|
|
return nil;
|
|
}
|
|
}
|
|
|
|
|
|
- (NSIndexPath*)tableView:(UITableView*)tableView indexPathForObject:(id)object {
|
|
NSUInteger objectIndex = [self.modelObjects indexOfObject:object];
|
|
if (objectIndex != NSNotFound) {
|
|
return [NSIndexPath indexPathForRow:objectIndex inSection:0];
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
- (NSString*)titleForEmpty {
|
|
return @"Empty!";
|
|
}
|
|
|
|
@end
|