uitableview的自定义单元格不可见

时间:2016-05-02 10:28:38

标签: ios objective-c uitableview

我正在使用tableview custom cell

我的自定义cell已贴上标签,我已在{StatutoryMappingCell.h'

定义了outlet

遵循isn cellForRowAtIndexPath方法,

StatutoryMappingCell * cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
if (!cell)
{
    [tableView registerNib:[UINib nibWithNibName:@"KnowledgeMainCell" bundle:nil] forCellReuseIdentifier:@"myCell"];
    cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
}

return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(StatutoryMappingCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.statMapping.text = [self.items objectAtIndex:indexPath.row];
}

问题是我运行代码时cells不可见。但为什么会这样呢?

这是我的xib场景...... enter image description here

这是我的故事板场景

enter image description here

2 个答案:

答案 0 :(得分:1)

查看您的界面构建器 - 您没有conntected您的自定义单元格,您应将其设置为files owner,如果是,则检查标签是否已连接,

答案 1 :(得分:1)

试试这些代码

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

  static NSString *CellIdentifier = @"identifier";
   CellItemList *cellA = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

   if (cellA == nil)
   {
       // Load the top-level objects from the custom cell XIB.
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:(isIpad)?@"CellItemList~ipad":@"CellItemList" owner:self options:nil];
      // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
      cellA = (CellItemList *)[topLevelObjects objectAtIndex:0];
   }
 cellA.statMapping.text = [tableData objectAtIndex:indexPath.row];

return cellA;
}
相关问题