我的(相当复杂的)情况如下:
TestView
是它的子类UIScrollView
implements-drawRect:
,但在内部的某个时刻,-drawRect:
它会调用一个方法,比如说-drawAnotherPartWithRect:context:
. 此方法由 的子类实现,TestView
以单独绘制上下文的某个部分。- 有两个子类
TestView
implement-drawAnotherPartWithRect:context:
,它们目前在其中做同样的事情:Subclass1
和Subclass2
. - 到目前为止,帧大小是初始化期间两者之间的唯一区别。
的一个实例Subclass1
用作表格视图的部分标题,它工作得很好,但如果Subclass2
用作单元格内容视图的子视图,它会显示,但不会滚动。其初始化如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PortoAppSubjectViewTableViewCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PortoAppSubjectViewTableViewCell"] autorelease];
Subclass2 *contentView = [[[Subclass2 alloc] initWithFrame:CGRectMake(0.f, 0.f, [tableView bounds].size.width, 32.f)] autorelease];
[contentView setContentSize:CGSizeMake(tableView.bounds.size.width * 3, 32.f)];
[contentView setTag:55];
[[cell contentView] addSubview:contentView];
}
[(SubjectTableViewCellContentView *)[[cell contentView] viewWithTag:55] setContainer:[[[[$container subGradeContainers] objectAtIndex:[indexPath section]] subGradeContainers] objectAtIndex:[indexPath row]]];
return cell;
}
有趣的是,水平滚动指示器出现并向我显示它正在很好地滚动,但文本(使用 CoreText 绘制)并没有随之左右移动。开箱即用Subclass1
。此外,如果Subclass2
用作节标题视图的视图类,它会很好地工作。
那么,水平滚动视图和表格视图单元格是怎么回事?我已经检查了关于 SO 的其他相关问题,但找不到任何解决方案。