未显示将子视图添加到UITableViewCell的情况
我通过 drawRect
@interface FTChartsView : UIView
@implementation FTChartsView
-(void)drawRect:(CGRect)rect
{
...
}
我也将UITableViewCell子类化
I have also subclassed the UITableViewCell
@interface FTSummaryCellView : UITableViewCell
...
现在,在ViewController中,当生成单元格时:
Now in the ViewController, when the cells are generated:
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"FTSummaryCellView" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:@"FTSummaryCellView"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FTSummaryCellView *cell = [tableView dequeueReusableCellWithIdentifier:@"FTSummaryCellView"];
FTChartsView *chart = [[FTChartsView alloc] init];
[cell addSubview:chart];
return cell;
}
单元格将chatrView添加为子视图.但是,ChartsView的 drawRect
永不中断,因此也不会显示.
The cell gets the chatrView added as subview. However chartsView's drawRect
, is never breaking and hence never showing.
请问我在这里想念什么?
What am I missing here please?
您忘记了 setFrame
.
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
TView *chart = [[TView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
[cell addSubview:chart];
return cell;
}
对我来说很完美.
Ty代表 [[self tableView] registerNib:nib forCellReuseIdentifier:@"FTSummaryCellView"];
.我从不知道这种方法)
Ty for [[self tableView] registerNib:nib forCellReuseIdentifier:@"FTSummaryCellView"];
. I never known about this method)
您必须将子视图添加到内容视图,如我所知.但是,所有这些对我来说都是有效的.
You must add subview to content view as I known. But all works for me without that.
[cell.contentView addSubview:chart];