【发布时间】:2012-12-06 20:44:00
【问题描述】:
我创建了一个自定义 UITableViewCell ,我正在从 xib 加载,所以现在文本可能是动态的,所以我希望 UILabel 的高度出现在 Custom UITableViewCell dynamic 中,
自定义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 的输出 旧 21.000000 新的 42.000000
【问题讨论】:
-
你得到正确的单元格高度了吗?是不是 noteDesc 用新框架调整了大小,但单元格的框架更小,所以 noteDesc 没有完全显示?
-
你所拥有的似乎还不错。尝试做 cell.noteDesc.frame = CGMake(0,0,50,50); cell.noteDesc.backgroundColor = [UIColor redColor];或者看看它是否在明确设置时改变它。这将排除错误的传递尺寸。
-
@TravisM。它不再影响了
-
我想我是从笔尖加载的,这可能是问题所在?
-
我认为这无关紧要。我从笔尖加载所有自定义表格单元格,我可以更改它们的属性。您确定您的 UILabel 已连接到您的子类中的 noteDesc 属性吗?
标签: iphone uitableview