当数据加载时,它显示完美的约束,并且数据以完美的间距完美显示......
表格加载时请查看附件:
当我们拥有较少的标题时,它会显示间距:
我正在从文件中加载数据:
代码如下:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Customviewcell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
UIImage * image = [UIImage imageNamed:justThumbs[indexPath.row]];
cell.Customimage.image=image;
cell.CustomTitle.text=justTitles[indexPath.row];
[cell.CustomTitle sizeToFit];
NSString * htmlString =justDesc[indexPath.row];
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
cell.CustomDes.attributedText=attrStr;
[cell.CustomDes sizeToFit];
[cell setNeedsDisplay];
[cell layoutIfNeeded];
return cell;
}
从文件中加载数据如下:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[tableviewcustom reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSURL * url = [[NSBundle mainBundle]URLForResource:@"services" withExtension:@"plist"];
Servicestitle = [NSDictionary dictionaryWithContentsOfURL:url];
justTitles = [Servicestitle objectForKey:@"Title"];
justThumbs= [Servicestitle objectForKey:@"Thumbnail"];
justDesc=[Servicestitle objectForKey:@"Description"];
tableviewcustom.estimatedRowHeight = 150;
tableviewcustom.rowHeight = UITableViewAutomaticDimension;
[tableviewcustom reloadData];
// Do any additional setup after loading the view, typically from a nib.
}
故事板如下:
为title和desc添加背景:
前3个细胞:
在前3个细胞之后:
非常感谢你的帮助。
答案 0 :(得分:0)
您可能希望使用此TableView委托的方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath