sim*_*nbs 2 iphone sdk height subclass uitableview
我有一个表格视图,其中细胞是子类.在子类中,我调用了UIView的子类.我已实现tableView:heightForRowAtIndexPath:并希望在我的子类中检索此高度以设置我的子类UIView的实例的高度.
有没有办法做到这一点?
我尝试过使用self.bounds.size.height,self.contentView.frame.size.height但这些都没有给出正确的高度.
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
textCellView = [[TextCellView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
[[self contentView] addSubview:textCellView];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
在创建时,子视图尚未定位,因此您无法依赖该框架.相反,尝试将值传递到自定义表格单元格上的init方法中.没有什么说你必须使用initWithStyle:reuseIdentifier:方法.这是一个例子:
- (id) initWithHeight: (CGFloat) cellHeight {
if ((self = [super initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: @"MyCustomTableViewCell"])) {
// perform all layout that needs to happen
// use cellHeight in all the layout calculations
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2448 次 |
| 最近记录: |