0

カスタム UITableViewCell を作成し、 xib からロードしているため、テキストが動的になる可能性があるため、 Custom UITableViewCell dynamic に存在する UILabel の高さが必要です。

カスタムUITableViewCellのコードは

    #import <UIKit/UIKit.h>

   @interface NarrativeCell : UITableViewCell
   @property(nonatomic,retain) IBOutlet UILabel *noteTitle;
   @property(nonatomic,retain) IBOutlet UILabel *noteDate;
   @property(nonatomic,retain) IBOutlet UILabel *noteDesc;
   @property(nonatomic,retain) IBOutlet UIImageView *sideImage;
   @property(nonatomic,retain) IBOutlet UIButton *imageButton;
   @property(nonatomic,retain) IBOutlet UIButton *audioStartButton; 
   @property(nonatomic,retain) IBOutlet UIButton *audioStopButton;

   @end

ここにコードがあります

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

      static NSString *CellIdentifier = @"NarrativeCell";


    NarrativeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil){
    NSLog(@"New Cell Made");

    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"NarrativeCell" owner:nil options:nil];

    for(id currentObject in topLevelObjects)
    {
        if([currentObject isKindOfClass:[NarrativeCell class]])
        {
            cell = (NarrativeCell *)currentObject;
            break;
        }
    }
}
Narratives *n=(Narratives *)[tableArray objectAtIndex:indexPath.row];

CGRect newFrame = cell.noteDesc.frame;


NSLog(@"old %f",newFrame.size.height);
newFrame.size.height = expectedLabelSize.height;
//yourLabel.frame = newFrame;
NSLog(@"new %f",newFrame.size.height);
 newFrame.size.height = expectedLabelSize.height;

[cell.noteDesc setFrame:newFrame];
[cell.noteDesc setNumberOfLines:0];

[cell.noteDesc setText:n.cfcnl_note];

return cell;

}

残念ながら、高さのサイズを変更することはできません

             [cell.noteDesc setFrame:newFrame];

nibファイルからロードしているため、UILabelの現在のカスタムUITableViewCell(nibで作成)の高さを動的に変更するにはどうすればよいか教えてください。

/////////編集

ここで old new の出力を参照してください old 21.000000 new 42.000000

4

1 に答える 1

0

セルがテキストに必要なサイズよりも小さいようです。したがって、heightForRowAtIndexpath メソッドを使用して、適切なセルの高さを見つける必要があります。このサイズ変更のためにセル内に十分なスペースがある場合は、XIB サブビュー階層を表示する必要があります。何か間違ったことをしているようです (ラベルを境界付けるスーパービュー クリップ)。

PSとにかく、インターフェースビルダーを使用しているからではありません。

于 2012-12-07T14:40:50.633 に答える