PAn Kaj Khatri PAn Kaj Khatri - 1 month ago 11
iOS Question

TableView not showing label ios

i am adding a table in NSObject calls so i can create the custom view.

tableView cellForRowAtIndexPath
is being called but not label is shown.
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;

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


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



Just edit the 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;