下面是无效的代码:
-(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;
}
答案 0 :(得分:0)
添加此方法。设置标签行数为0。
将此代码添加到表格视图中
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;
}