0

I have a UITableView within a View Controller. Very strange because the header is showing up and the header text but not the cell text.

- (void)viewDidLoad
{

table.delegate = self;
selection= [[NSMutableArray alloc] init];

[selection addObject:@"text"];
[selection addObject:@"text"];
[selection addObject:@"text"];
...}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// configure the cell in each row

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease]; 
}
NSString *cellValue = [selection objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
//  cell.textColor=[UIColor blackColor];
    return cell;
}
4

1 回答 1

1

尝试添加此行

table.dataSource = self;

这样,只要你的类符合 UITableViewDataSource 协议,所有的表格视图数据源方法(包括 cellForRowAtIndexPath:) 都会被调用。

于 2013-07-24T15:36:39.017 回答