2011-07-31 5 views
1

를 호출 할 수 없습니다 willDisplayCell :은 왜 이런 식으로 내 MainPageDataSource.m의 I 코드

#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

사실 TTTableViewDataSource 클래스에는 그러한 기능이 없다는 것을 고려해 볼 때 왜 호출해야하는지 잘 모르겠습니다.

어쩌면 당신은이 기능을 의미 :

이 기능은 테이블 셀이 TTTableView에 표시 될 때마다 호출되는
- (void)tableView:(UITableView*)tableView cell:(UITableViewCell*)cell 
    willAppearAtIndexPath:(NSIndexPath*)indexPath; 

. 나는 그것을 사용할 필요가 전혀 없었다. 모든 논리를 테이블 셀 클래스에 보관하는 것이 더 좋습니다.

+0

음, thanks @aporat. 셀 배경색을 설정하고 싶습니다. 그래서 그것을 설정하는 더 좋은 방법이 있다면. 말해줘. 그리고 cellForRowAtIndexPath를 사용하는 코드를 업데이트했습니다. 이번에는 cellForRowAtIndexPath를 호출 할 수 있지만, tableForDidLoadModel cellForRowAtIndexPath의 설정은 데이터를 덮어 덮어 두었습니다. –

+0

cool! @ 방울을 그냥 만들어! 감사! 그러나 나는 방금 물었던 질문을 알아 내고 싶다. ... –

+0

사용자 정의 셀 클래스가 이미있는 경우 CustomTTTableSubtitleItemCell의 init 함수에서 배경색을 설정할 수 있습니다. – aporat

관련 문제