为什么带子视图的UITableView不显示任何数据?

时间:2011-03-06 14:41:33

标签: iphone objective-c uitableview

我正在尝试使用子视图创建UITableView,并且我使用了我找到的教程。但是,我无法在表格上显示任何数据,没有错误。

想问一下是否有人可以查看代码并给我一个提示如何使其工作?

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {

CGRect CellFrame = CGRectMake(0, 0, 300, 60);
CGRect Label1Frame = CGRectMake(10, 10, 290, 25);
CGRect Label2Frame = CGRectMake(10, 33, 290, 25);
UILabel *lblTemp;

UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];

//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
[cell.contentView addSubview:lblTemp];
[lblTemp release];

//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
lblTemp.font = [UIFont boldSystemFontOfSize:12];
lblTemp.textColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];
return cell;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)
    cell = [self getCellContentView:CellIdentifier];

UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];

//First get the dictionary object
//  NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [[NSArray alloc]initWithObjects: @"One", @"Two", @"Three", nil]; 
NSString *cellValue = [array objectAtIndex:indexPath.row];

lblTemp1.text = cellValue;
lblTemp2.text = @"Sub Value";

[cellValue release];


return cell;

}

1 个答案:

答案 0 :(得分:2)

非常基本的问题,但是您确定要设置需要在表格视图中显示的行数和部分数吗?如果您设置了断点,是否可以看到正在调用tableView:cellForRowAtIndexPath: