objective-cuitableviewthree20

Why willDisplayCell not be called


in my MainPageDataSource.m I code like this:

#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 never been called. What's wrong?


Solution

  • Considering the fact there's no such function in the TTTableViewDataSource class, i'm not sure why it should be called.

    maybe you mean this function:

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

    This function get called each time a table cell is displayed in the TTTableView. I never had the need to use it. I think it's better to keep all the logic in the table cell classes.