1
這樣的:爲什麼willDisplayCell不能叫我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從來沒有被調用。怎麼了?
嗯,謝謝@aporat。我只想設置單元格背景顏色。所以如果有更好的方法來設置它。請告訴我。我更新了我使用cellForRowAtIndexPath的代碼,這次可以調用cellForRowAtIndexPath,但似乎tableViewDidLoadModel cellForRowAtIndexPath中的設置覆蓋了數據集 –
cool! @aporat你的方式剛剛做到了!謝謝!但我仍想弄清楚我剛剛問過的問題。如果您有時間... –
如果您已經有自定義單元類,可以在CustomTTTableSubtitleItemCell的init函數中設置背景顏色。 – aporat