我正在尝试动态更改高度,但不知何故它不起作用。“detailText”标签与列表的其他字段重叠。整个单元格的默认高度为 150,包括用户、文本、日期。用户和日期各占一行,其余的为文本。我正要完成应用程序,但这确实扰乱了整个过程,我还检查了其他技术,但不知何故,它们都不起作用。可能是我错过的一件小事。:(
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *user=[[discussionArray objectAtIndex:indexPath.row] objectForKey:@"user"];
NSString *text=[[discussionArray objectAtIndex:indexPath.row] objectForKey:@"text"];
NSString *time=[[discussionArray objectAtIndex:indexPath.row] objectForKey:@"date"];
CGSize usersize = [user sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(250, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
CGSize textsize = [text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(250, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
CGSize timesize = [time sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(250, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
return usersize.height+textsize.height+timesize.height;
}
和连接器
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
discussionCustomCell *cell = (discussionCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"discussionCustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSLog(@"%i",[discussionArray count]);
NSDictionary *dict=[discussionArray objectAtIndex:indexPath.row];
cell.imageViewIst.image = [profileImagesArray_ objectAtIndex:indexPath.row];
NSString *new=[dict objectForKey:@"new"];
if ([new isEqualToString:@"0"])
{
cell.imageViewSecond.backgroundColor=[UIColor redColor];
}
else
{
cell.imageViewSecond.backgroundColor=[UIColor greenColor];
}
cell.nameLabel.text=[dict objectForKey:@"user"];
cell.nameLabel.font = [UIFont boldSystemFontOfSize:15];
cell.nameLabel.numberOfLines = ceilf([[dict objectForKey:@"user"] sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(250, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap].height/20.0);
cell.detailText.text=[dict objectForKey:@"text"];
cell.detailText.font = [UIFont boldSystemFontOfSize:15];
cell.detailText.numberOfLines = ceilf([[dict objectForKey:@"text"] sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(250, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap].height/20.0);
cell.timeLabel.text=[dict objectForKey:@"date"];
cell.timeLabel.font = [UIFont boldSystemFontOfSize:15];
cell.timeLabel.numberOfLines = ceilf([[dict objectForKey:@"date"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(250, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap].height/20.0);
return cell;
}