Objective c 为什么不调用DisplayCell
在我的MainPageDataSource.m中,我的代码如下:Objective c 为什么不调用DisplayCell,objective-c,uitableview,three20,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 {
#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
#导入“MainPageDataSource.h”
#导入“LoadResult.h”
#导入“CustomTTTableSubtitleItem.h”
#导入“CustomTTTableSubtitleItemCell.h”
#导入“XYDefaultStylesheet.h”
@实现MainPageDataSource
-(id)init{
if(self=[super init]){
_mainPageModel=[[MainPageMode alloc]init];
_allResults=[[NSMutableArray alloc]init];
}
回归自我;
}
-(id)模型{
返回_mainPageModel;
}
-(void)tableViewDidLoadModel:(UITableView*)tableView
{
[超级tableViewDidLoadModel:tableView];
NSDateFormatter*dateFormat=[[NSDateFormatter alloc]init];
[日期格式setDateFormat:@“yyyy-MM-dd”];
对于(LoadResult*结果为[(id)self.model结果]){
NSTimeInterval formateSeconds=[result.resourceVersionTime doubleValue];
NSString*dataFormatted=[dateFormat stringFromDate:[NSDate DateWithTimeIntervalences1970:formateSeconds]];
NSString*textCombine=[dataFormatted stringByAppendingFormat:@/%/%@\n%@],
result.resourceVersion、result.resourceSize、result.resourceCatalog];
[self.items addObject:[CustomTTTableSubTitleItemWithTitle:result.resourceName文本:textCombine]
imageURL:result.resourceImagepath URL:nil
右按钮:result.resourcePrice通知:result.resourceRate]];
}
TT_安全发布(日期格式);
}
-(类)tableView:(UITableView*)tableView cellClassForObject:(id)对象{
如果([object isKindOfClass:[CustomTTTableSubtitleItem class]]){
返回[CustomTTTableSubtitleItemCell类];
}否则{
返回[super tableView:tableView cellClassForObject:object];
}
}
-(void)tableView:(UITableView*)tableView prepareCell:(UITableView单元格*)rowatindexpath的单元格:(nsindepath*)indepath{
cell.accessoryType=UITableViewCellAccessoryNone;
}
-(UITableView单元格*)表格视图:(UITableView*)表格视图
cellForRowAtIndexPath:(NSIndexPath*)indexPath{
NSLog(@“indexPath.row11111====%d”,indexPath.row);
UITableViewCellStyle=UITableViewCellStyleValue2;
CustomTTableSubtitleItemCell*单元格=(CustomTTableSubtitleItemCell*)[tableView dequeueReusableCellWithIdentifier:@“CustomTTableSubtitleItemCell]”;
如果(单元格==nil){
NSLog(“新le电池”);
cell=[[CustomTTableSubtitleItemCell alloc]initWithStyle:style重用标识符:@“CustomTTableSubtitleItemCell”]自动释放];
}
if(indexath.row%2==0){
cell.contentView.backgroundColor=TTSTYLEVAR(tableCellColor1);
}否则{
cell.contentView.backgroundColor=TTSTYLEVAR(tableCellColor2);
}
返回单元;
}
-(无效)解除锁定{
TT_安全释放(_mainPageModel);
[super dealoc];
}
@结束
willDisplayCell从未被调用过。怎么了?考虑到
TTTableViewDataSource
类中没有这样的函数,我不确定为什么应该调用它
也许你指的是这个函数:
- (void)tableView:(UITableView*)tableView cell:(UITableViewCell*)cell
willAppearAtIndexPath:(NSIndexPath*)indexPath;
每次在TTTableView中显示表格单元格时,都会调用此函数。
我从来没有必要使用它。我认为最好保留表单元格类中的所有逻辑。考虑到
TTTableViewDataSource
类中没有这样的函数,我不确定为什么应该调用它
也许你指的是这个函数:
- (void)tableView:(UITableView*)tableView cell:(UITableViewCell*)cell
willAppearAtIndexPath:(NSIndexPath*)indexPath;
每次在TTTableView中显示表格单元格时,都会调用此函数。
我从来没有必要使用它。我认为最好将所有逻辑保留在表单元格类中。好的,谢谢@aporat。我只想设置单元格的背景色。因此,如果有更好的方法设置它。请告诉我。我更新了使用CellForRowatineXpath的代码。这次可以调用CellForRowatineXpath,但tableViewDidLoadModel CellForRowatineXpath中的设置似乎覆盖了数据集incool@你的方式刚刚成功!!!谢谢但我还是想弄清楚我刚才问的问题。如果您有时间…如果您已经有自定义单元格类,您可以在CustomTTTableSubtitleItemCell的init函数中设置背景色。好的,谢谢@aporat。我只想设置单元格的背景色。因此,如果有更好的方法设置它。请告诉我。我更新了使用CellForRowatineXpath的代码。这次可以调用CellForRowatineXpath,但tableViewDidLoadModel CellForRowatineXpath中的设置似乎覆盖了数据集incool@你的方式刚刚成功!!!谢谢但我还是想弄清楚我刚才问的问题。如果您有时间…如果您已经有自定义单元格类,您可以在CustomTTTableSubtitleItemCell的init函数中设置背景色。