2

カスタムtableViewCellクラスのセルを複数行にして折り返すようにしました。ここでQ&Aを読み、指示に従いますが、それでも解決策を見つけることができません。

コンテンツの長さごとに動的な高さを調整できますが、それでも作成できません。これが私のコードです

-(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で行をゼロに設定し、改行をワードラップに設定しましたが、期待どおりに表示されません。

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 に答える