【发布时间】:2013-03-26 10:36:55
【问题描述】:
我尝试将自定义 tableViewCell 类中的单元格设置为多行并换行。
我在这里阅读了我的问答并按照说明进行操作,但仍然找不到解决方案。
我可以调整每个内容长度的动态高度,但仍然无法使 这是我的代码
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomItemCell"];
if(cell == nil){
cell = [[CustomItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomItemCell"];
//I set lineBreakMode of cell.postLabel to NSLineBreakByWordWrapping
// and set numberofLines = 0 ;
cell.postLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.postLabel.numberOfLines = 0;
}
CustomItem *item = [[channel items] objectAtIndex:[indexPath row]];
//postLabel is the label that I want to be multiline and wordwrap
// postLabel get an NSString from [item post]
[[cell postLabel] setText:[item post]];
[[cell timeLabel] setText:[item time]];
[[cell distanceLabel] setText:[item distance]];
[[cell thumbnailView] setImage:[item thumbnail]];
return cell;
}
我创建了CustomItemCell.xib 文件。实际上,我还在界面生成器中将行设置为零并将换行符设置为自动换行,但它没有像我预期的那样显示。
【问题讨论】:
-
如果您根据其内容设置标签高度,则标签可以是多行并换行
-
如果
postLabel有问题,最简单的尝试方法是在设置文本后致电[[cell postLabel] sizeToFit]。还要小心将postLabel添加到单元格的contentView。 -
高度已经设置,但没有任何改变。
-
Marko,我在 CustomItemCell.xib 中设置了我的单元格。我是否必须再次将其添加到内容视图中?
标签: ios iphone uitableview cocoa-touch uilabel