- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = @"cell自适应高度";
cell.textLabel.frame = CGRectMake(0, 0, 100, 100); // 设置textLable 高度
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.textLabel.frame.size.height; // 返回textLabel的高度,在这里可以根据你cell上的内容设置cell的高度
}
UITableViewCell根据内容自适应高度
最新推荐文章于 2017-05-15 17:12:16 发布