Implement custom cell in TTTableView to a TTViewController
I have TTViewController include a TTTableView inside and init TTTableView like below:
- (void)loadView{
appTableView = [[TTTableView alloc] initWithFrame:CGRectMake(10, 20, self.view.width - 20, (self.view.height - 44 - 49)/2 - 40)];
appTableView.backgroundColor = [UIColor clearColor];
appTableView.delegate = self;
appTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:appTableView];
}
and in
- (void)requestDidFinishLoad:(TTURLRequest*)request {
appTableView.dataSource = [TTListDataSource dataSourceWithObjects:
[CustomTTTableSubtitleItem itemWithTitle:result.resourceName text:textCombine ],nil];
}
I've coded this:
- (Class)tableView:(UITableView*)tableView cellClassForOb开发者_开发问答ject:(id) object {
if ([object isKindOfClass:[CustomTTTableSubtitleItem class]]) {
NSLog(@"here");
return [CustomTTTableSubtitleItemCell class];
}
else {
return [self tableView:tableView cellClassForObject:object];
}
}
and of course I added protocol
@interface TestController : TTViewController<TTTableViewDelegate,TTTableViewDataSource>
but seems -(Class)tableView:(UITableView*)tableView cellClassForObject:(id) object not be called... anything I missed?
the - (Class)tableView:(UITableView*)tableView cellClassForObject:(id) object
is a TTTableViewDataSource function, so you will have to extend the TTListDataSource into your own data source class, and override this function there and not under TTViewController.
In your TTViewController, create the custom data source:
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)requestDidFinishLoad:(TTURLRequest*)request {
self.dataSource = [[[YourDataDataSource alloc]
initWithResults:results] autorelease];
}
and in your custom TTTableViewDataSource have your - (Class)tableView:(UITableView*)tableView cellClassForObject:(id) object
custom function
精彩评论