TableView 不显示标签 ios

TableView not showing label ios

我正在 NSObject 调用中添加一个 table,这样我就可以创建自定义视图。 但是正在调用 tableView cellForRowAtIndexPath 但未显示标签。 我查看了一个视图并在该视图上添加了 table 并在超级 class.

中添加了该视图

代码如下:

- (id)initWithFrame:(CGRect)frame
{
self = [super init]; //calls init because UIResponder has no custom init methods
if (self){
    [self allocViewWithFrame:frame];
}
return self;
}

-(void)allocViewWithFrame:(CGRect)frame{
view = [[UIView alloc]initWithFrame:frame];

TableViewChat =[[UITableView alloc]initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)];
TableViewChat.delegate = self;
TableViewChat.dataSource = self;
[view addSubview:TableViewChat];
dispatch_async(dispatch_get_main_queue(), ^{
    [TableViewChat reloadData];
});

}

#pragma mark- tableView delegate and data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 144.0f;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableCell"];

if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                  reuseIdentifier:@"SimpleTableCell"];

}

cell.textLabel.text = @"Cell";
return cell;

}

在 cellForRowAtIndexPath 中

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

   static NSString *strCellIdentifier = @"CellIdntifier";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellIdentifier];
   if(cell == nil)
   {
      cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCellIdentifier];
   }

  cell.titleLabel.text = @"First" 

  return cell;
}

只需编辑 cellForRowatIndexPath

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


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdntifier"];
if(cell == nil)
{
  cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCellIdentifier];
}

cell.titleLabel.text = @"First" 

return cell;
}