UITableViewCell和标签不显示文本

时间:2014-09-02 15:46:38

标签: ios objective-c uitableview

我有一个UITableView,其中包含一个包含两个标签的单元格。表视图链接到dataSource和delegate,单元格中的标签链接到IBOutlet,不是。它看起来像这应该工作,但下面的代码没有运行所以单元格或标签没有填充文本。有任何想法吗?或者我遗失的任何东西?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"theLabelCell";
CustomClassCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

CustomClassText *customText = _arrayThatHasText[indexPath.row];


if (![self isSelectionMode]) {
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

cell.TitleLabel.text = customText.firstLabel;
cell.TextLabel.text = customText.secondLabel;

return cell;
}

3 个答案:

答案 0 :(得分:1)

您是否记得还要注册小区标识符以供重用?

- (void)viewDidLoad    
{
    [super viewDidLoad];

    [self.tableView registerNib:[UINib nibWithNibName:@"CustomClassCell" bundle:nil] forCellReuseIdentifier:@"theLabelCell"];
} 

答案 1 :(得分:1)

如果您没有看到任何单元格,请检查numberofSectionsnumberOfRowsInSection委托方法是否未返回0

答案 2 :(得分:1)

您的_arrayThatHasText何时填充?问题很可能是数据源(_arrayThatHasText)在调用numberofSectionsnumberOfRowsInSection委托方法之前被实例化,然后在调用这些方法之后数据源正在被填充实际数据 - >这将导致您遇到委托方法中的0值。

您可能希望尝试在[self.tableView reloadData]ViewWillAppear方法结束时发出ViewDidAppear来电,看看是否有帮助。

相关问题