为什么不会调用DisplayCell

时间:2011-07-31 17:14:34

标签: objective-c uitableview three20

在我的MainPageDataSource.m中我的代码如下:

#import "MainPageDataSource.h"
#import "LoadResult.h"
#import "CustomTTTableSubtitleItem.h"
#import "CustomTTTableSubtitleItemCell.h"
#import "XYDefaultStylesheet.h"


@implementation MainPageDataSource


- (id)init {
if (self = [super init]) {
    _mainPageModel = [[MainPageMode alloc] init];
    _allResults = [[NSMutableArray alloc] init];                   
}
return self;
}


- (id<TTModel>)model {
    return _mainPageModel;
}


- (void)tableViewDidLoadModel:(UITableView*)tableView 
{

[super tableViewDidLoadModel:tableView];

NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];   

[dateFormat setDateFormat:@"yyyy-MM-dd"];
for (LoadResult *result in [(id<TabModel>)self.model results]){
    NSTimeInterval formateSeconds = [result.resourceVersionTime doubleValue];
    NSString *dataFormatted =[dateFormat stringFromDate:[NSDate dateWithTimeIntervalSince1970:formateSeconds]]; 

    NSString *textCombine = [dataFormatted stringByAppendingFormat:@"/%@/%@\n%@", 
                             result.resourceVersion, result.resourceSize, result.resourceCatalog];





    [self.items addObject:[CustomTTTableSubtitleItem itemWithTitle:result.resourceName text:textCombine 
                                                          imageURL:result.resourceImagepath URL:nil
                                                  rightButtonTitle:result.resourcePrice appRate:result.resourceRate]];


}


    TT_RELEASE_SAFELY(dateFormat);


}

- (Class)tableView:(UITableView*)tableView cellClassForObject:(id) object { 

if ([object isKindOfClass:[CustomTTTableSubtitleItem class]]) { 
    return [CustomTTTableSubtitleItemCell class];       
} else { 
    return [super tableView:tableView cellClassForObject:object]; 
}
}



- (void)tableView:(UITableView*)tableView prepareCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath {
cell.accessoryType = UITableViewCellAccessoryNone;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"indexPath.row11111 ===== %d",indexPath.row);
UITableViewCellStyle style =  UITableViewCellStyleValue2;
CustomTTTableSubtitleItemCell *cell = (CustomTTTableSubtitleItemCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomTTTableSubtitleItemCell"];
if (cell == nil) {
    NSLog(@"new le cell");
    cell = [[[CustomTTTableSubtitleItemCell alloc] initWithStyle:style reuseIdentifier:@"CustomTTTableSubtitleItemCell"] autorelease];

}

if (indexPath.row % 2 == 0) {
    cell.contentView.backgroundColor = TTSTYLEVAR(tableCellColor1);
}else {
    cell.contentView.backgroundColor = TTSTYLEVAR(tableCellColor2);
}

return cell;
}



- (void)dealloc {
TT_RELEASE_SAFELY(_mainPageModel);
[super dealloc];
}

@end

willDisplayCell从未被调用过。怎么了?

1 个答案:

答案 0 :(得分:1)

考虑到TTTableViewDataSource类中没有这样的功能,我不确定为什么要调用它。

也许你的意思是这个功能:

 - (void)tableView:(UITableView*)tableView cell:(UITableViewCell*)cell
    willAppearAtIndexPath:(NSIndexPath*)indexPath;

每次在TTTableView中显示表格单元格时,都会调用此函数。 我从来没有必要使用它。我认为最好将所有逻辑保留在表格单元类中。