我创建了一个自定义 UITableViewCell ,并且从 xib 加载,所以现在文本可能是动态的,所以我希望 UILabel 的高度出现在自定义 UITableViewCell 动态中,
自定义 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 21.000000 new 42.000000 的输出