0

刚刚创建了一个 UITableView,

试图从数组中显示一些自定义数据,但无论我做什么,我都没有显示任何文本。

NSLog 告诉我正确的文本和正确的数量,但表格单元格中没有文本。

这是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = @"test";

    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}
4

2 回答 2

3

检查事项:

cellForRowAtIndexPath被叫了吗?在里面放一个断点

在 ViewDidLoad (property, alloc'd) 中创建一个数组,addObjects @"One", @"Two", @"Three", nil然后cell.textLabel.text = [theArray objectAtIndex:indexPath.row];

如果cellForRow被调用,这将显示在单元格中。做什么ConfigureCell?请包括代码。

还要检查您的 tableView 委托方法是否被调用(NumberofRowsInSection等)

于 2012-07-24T16:40:40.500 回答
0

始终在

tableView:willDisplayCell:forRowAtIndexPath 

委托方法。

UITableView 有时会在从单元格返回后向单元格发送 prepareForReuse

tableView:cellForRowAtIndexPath

这会导致单元格重置其标签和图像。

于 2012-07-24T18:20:30.090 回答