1

enter image description here

enter image description here

Below is the code that is not working:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"Cell";

    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    MessageObject *currentdatas = [self.objectHolderArray objectAtIndex:indexPath.row];

    cell.Name_Label.text = currentdatas.Name;
    //Here I wanted to adjust my label height according to my message received

    cell.Message_Label.text = currentdatas.MSG;
    [cell.Message_Label sizeToFit];

    NSTimeInterval timeInterval = currentdatas.time/1000;
    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-mm-yyyy"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    NSLog(@"My date %@",dateString);
    cell.Time_Label.text = dateString;

    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:currentdatas.Profile]]];
    // Image Rectangle to circular
    cell.Image_View.image = image;
    cell.Image_View.layer.cornerRadius = cell.Image_View.frame.size.width/2;
    cell.Image_View.clipsToBounds = YES;

    return cell;
}
Kuldeep
  • 4,466
  • 8
  • 32
  • 59
Minato
  • 302
  • 3
  • 15

1 Answers1

0

add this method.set label number of lines 0.

add this code in tableview

self.tableView.estimatedRowHeight = 80;
self.tableView.rowHeight = UITableViewAutomaticDimension;

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {

   return UITableViewAutomaticDimension; 
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

enter image description here

enter image description here

Jigar
  • 1,801
  • 1
  • 14
  • 29