我正在为我的视图实现一个表视图控制器。作为苹果文档中的具体细节,我UITableViewCellStyleSubtitle
在表格中使用了我的单元格。
我需要的是一个单元格,左侧包含一个小头像,粗体textLabel
和较小的detailTextLabel
. 两者textLabel
和detailTextLabel
都是多行,而不仅仅是一行。
我正在尝试链接中的教程,但模拟器只显示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
for的内容textDetailLabel
。它还没有包含头像。如果有人可以帮助我解决此问题并将较小的头像添加到此表格视图单元格中,我将不胜感激。