2

我试图使我的自定义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文件。实际上,我还在界面生成器中将行设置为零并将换行符设置为自动换行,但它没有像我预期的那样显示。

4

2 回答 2

2

尝试这个,

[cell.postLabel sizeToFit];
于 2013-03-26T11:09:06.243 回答
1

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

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

核实..

于 2013-03-26T11:57:16.273 回答