我为我的视图实现了表视图控制器。作为苹果文档中的具体细节,我在表中使用了UITableViewCellStyleSubtitle
作为我的单元格。UItable查看单元格textLabel,detailTextLabel和UIImage
我需要的是一个单元格包含左侧的小化身,大胆的textLabel
和更小的detailTextLabel
。 textLabel
和detailTextLabel
都是多行,不只一行。
我正在尝试从link的教程,但模拟器只显示textLabel
。
这里是我的cellForRowAtIndexPath:
方法:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [newsTitle objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont boldSystemFontOfSize:18];
cell.textLabel.numberOfLines = ceilf([[newsTitle objectAtIndex:indexPath.row] sizeWithFont:[UIFont boldSystemFontOfSize:18] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap].height/20);
cell.detailTextLabel.text = [newsDescription objectAtIndex:indexPath.row];
cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
cell.detailTextLabel.numberOfLines = ceilf([[newsTitle objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap].height/20);
return cell;
}
这里是heightForRowAtIndexPath:
方法:
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *titleString = [newsTitle objectAtIndex:indexPath.row];
NSString *detailString = [newsDescription objectAtIndex:indexPath.row];
CGSize titleSize = [titleString sizeWithFont:[UIFont boldSystemFontOfSize:18] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
CGSize detailSize = [detailString sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
return detailSize.height+titleSize.height;
}
注:阵列newsTitle
保持textLabel
内容,newsDescription
为textDetailLabel
。它尚未包含头像。我非常感谢,如果有人可以帮助我解决这个问题,并将小型化身添加到这个表格视图单元格。
也u必须设置为textLabel和detailTextLabel的高度'cellForRowAtIndexPath'方法.. – vishy
做你的解决方案或不? – Pratik