简体   繁体   中英

UITableViewCell and label not displaying text

I have a UITableView with a cell that has two labels in it. The table view is linked to the dataSource and delegate, the labels in the cell are linked to an IBOutlet, what not. It looks to me like this should work, but this code below is not running so the Cell or labels are not populated with text. Any ideas? Or anything I'm missing?

- (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;
}

Did you remember to also register the cell identifier for reuse?

- (void)viewDidLoad    
{
    [super viewDidLoad];

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

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

When does your _arrayThatHasText get populated? The issue might very well be that the data source ( _arrayThatHasText ) is getting instantiated before the numberofSections and numberOfRowsInSection delegate methods are being called and then after these methods are called the data source is being populated with actual data -> which would result in the 0 values in the delegate methods as you are experiencing.

You might want to try putting a [self.tableView reloadData] call at the end of ViewWillAppear or in ViewDidAppear method and see if that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM