开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜