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

发布于 2024-12-02 09:23:58 字数 93 浏览 0 评论 0原文

我使用 UISegmentedControl 作为表视图的标题视图。现在我想添加加载视图(我自己定义的视图),仅覆盖表格单元格,但不覆盖我的标题视图。我该如何实现这一目标?

I'm using a UISegmentedControl as the headerview of a tableview. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没有 2024-12-09 09:23:58

您可以将此视图添加到所需的单元格中:

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

You can add this view to the cell you want:

UITableViewCell *cell = [self tableView:self.tableView cellForRowAtIndexPath:indexPathOfCell];
[cell addSubview:view];
二货你真萌 2024-12-09 09:23:58

添加加载视图的最简单方法是这样的

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

* 将视图添加到窗口可能不是您设计的最佳选择,但由于我不知道视图层次结构的任何细节,因此这就是永远会起作用。

注意:如果您没有遮盖分段控件,并且启用了它,则用户可能会在您不期望的情况下单击它并更改应用程序的状态 - 例如当您尝试加载某些内容时对于他们来说。确保如果用户更改应用的状态,您可以取消此加载视图。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文