简体   繁体   English

如何将子视图添加到仅覆盖表单元格但不覆盖表头视图的表视图

[英]How to add a subview to a tableview only covering the table cell but not the table header view

I'm using a UISegmentedControl as the headerview of a tableview. 我使用UISegmentedControl作为tableview的headerview。 Now I want to add loading view (a view defined by myself) only covering the table cells but not my headerview. 现在,我想添加仅覆盖表格单元而不是标题视图的加载视图(由我自己定义的视图)。 How do I achieve this? 我该如何实现?

You can add this view to the cell you want: 您可以将此视图添加到所需的单元格中:

UITableViewCell *cell = [self tableView:self.tableView cellForRowAtIndexPath:indexPathOfCell];
[cell addSubview:view];

The simplest way to add the loading view would be like this 添加加载视图的最简单方法是这样的

// 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];

* Adding the view to the window may not be the best thing for your design, but since I don't know any of the details of your view hierarchy, this is the way that will always work. *将视图添加到窗口可能不是您设计的最佳选择,但是由于我不知道您的视图层次结构的任何细节,因此这将始终有效。


Caution: If you do not cover up the segmented control, and it is enabled, the user may click on it and change the state of the app when you aren't expecting it - like when you're trying to load something for them. 警告:如果您没有掩盖分段控件,并且已启用该控件,则用户可以在不期望它的情况下单击它并更改应用程序的状态-例如,当您尝试为其加载某些内容时。 Be sure that you can cancel this loading view if the user changes the state of the app. 如果用户更改了应用程序的状态,请确保可以取消此加载视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM