从未调用过cellForRowAtIndexPath

时间:2010-09-01 13:15:54

标签: iphone uitableview ios4

我已经将UITableView子类化,以创建我自己的数据检索系统,如Apple自己的核心数据教程中所述,但我遇到了问题。我的自定义表中的替代cellForRowAtIndexPath方法永远不会被调用,即使我调用reloadData或setNeedsDisplay也是如此。我一直在寻找这个问题的解决方案,似乎这个错误可能是由许多问题引起的。但是我已经检查了所有我能找到的并且看不到任何遗漏的东西。谁能告诉我什么可能是错的?

P.S。我知道UITableViewDataSource协议需要在三角括号中,但我无法找到如何在页面上显示三角括号而不删除它们之间的文本。

H-文件

@interface DataTable : UITableView <UITableViewDataSource> {
    NSMutableArray *list;
}

@property (nonatomic, retain) NSMutableArray *list;

@end


M-文件
@implementation DataTable

@synthesize list;

-(id) initWithFrame:(CGRect)rect Style:(UITableViewStyle)style{ if (self = [super initWithFrame:rect style:style]){ list = [[NSMutableArray alloc] init]; self.dataSource = self; } return self; }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [list count]; }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellID = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil){ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID] autorelease]; }

    CH *this = (CH *)[list objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [this.clusterName mutableCopy]; return cell; }

-(void) dealloc{ [list release]; [super dealloc]; }

@end

1 个答案:

答案 0 :(得分:2)

没关系,想想我找到了它。基本上,您无法在程序的该部分中设置数据源委托。需要从拥有的视图控制器中完成。

相关问题