Ios 自定义TableViewCell中的标签可以';不能是多行或换行

Ios 自定义TableViewCell中的标签可以';不能是多行或换行,ios,iphone,uitableview,cocoa-touch,uilabel,Ios,Iphone,Uitableview,Cocoa Touch,Uilabel,我尝试将自定义tableViewCell类中的单元格设置为多行和换行。 我在这里阅读了我的问答,并按照说明进行操作,但仍然无法找到解决方案 我可以调整每个内容长度的动态高度,但仍然无法使 这是我的密码 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomItemCell *cell = [tableView dequeueR

我尝试将自定义
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
文件。实际上,我还在interface builder中将行设置为零,并将换行符设置为wordwrap,但它并没有像我预期的那样显示出来

试试这个

[cell.postLabel sizeToFit];

为多行设置单元格样式,如下所示

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];

检查它。

如果您根据标签的内容设置标签高度,标签可以是多行和换行的。如果您的
postLabel
有问题,最好的尝试方法是在设置文本后调用
[[cell postLabel]sizeToFit]
。还要注意将
postLabel
添加到单元格的
contentView
。高度已设置,但不会改变任何内容。Marko,我已在CustomItemCell.xib中设置了单元格。是否必须再次将其添加到内容视图?已尝试。但是没有起作用。。。我把它放在[[cell postLabel]setText:[item post]]下面;我发现了问题。界面生成器已启用“使用自动布局”。我禁用了此选项,sizeToFit可以完美工作