简体   繁体   English

TableView不显示标签iOS

[英]TableView not showing label ios

i am adding a table in NSObject calls so i can create the custom view. 我在NSObject调用中添加了一个表,以便可以创建自定义视图。 But tableView cellForRowAtIndexPath is being called but not label is shown. 但是正在调用tableView cellForRowAtIndexPath ,但未显示标签。 i have taken a view and adding the table on that view and added this view in the super class. 我已经采取了一个视图,并在该视图上添加表,并在超类中添加了此视图。

The code is as below: 代码如下:

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

}

In cellForRowAtIndexPath 在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;
}

Just edit the cellForRowatIndexPath 只需编辑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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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