【发布时间】:2011-09-01 15:03:45
【问题描述】:
我使用 UISegmentedControl 作为 tableview 的 headerview。现在我想添加加载视图(我自己定义的视图)只覆盖表格单元格而不是我的标题视图。我如何做到这一点?
【问题讨论】:
标签: iphone xcode uitableview subview
我使用 UISegmentedControl 作为 tableview 的 headerview。现在我想添加加载视图(我自己定义的视图)只覆盖表格单元格而不是我的标题视图。我如何做到这一点?
【问题讨论】:
标签: iphone xcode uitableview subview
您可以将此视图添加到您想要的单元格中:
UITableViewCell *cell = [self tableView:self.tableView cellForRowAtIndexPath:indexPathOfCell];
[cell addSubview:view];
【讨论】:
添加加载视图的最简单方法是这样的
// get the frame of your table header view
CGRect headerFrame = headerView.frame;
// construct a frame that is the screen minus the space for your header
CGRect loadingFrame = [[UIScreen mainScreen] applicationFrame];
loadingFrame.origin.y += headerFrame.size.height;
loadingFrame.size.height -= headerFrame.size.height;
// use that frame to create your loading view
MyLoadingView *loadingView = [[MyLoadingView alloc] initWithFrame:loadingFrame];
// add your view to the window *
[[headerView window] addSubview:loadingView];
* 将视图添加到窗口可能不是您设计的最佳选择,但由于我不知道您的视图层次结构的任何细节,因此这种方式将始终有效。
注意:如果您不隐藏分段控件,并且它已启用,则用户可能会在您不期望的情况下单击它并更改应用程序的状态 - 就像当您'正试图为他们加载一些东西。如果用户更改了应用程序的状态,请确保您可以取消此加载视图。
【讨论】:
[headerView window],您将能够很快就弄清楚了。