ios - 添加到 super View 的 View 在导航 TableView 时消失

标签 ios objective-c tableview superview

我有一个 tableView,当用户选择其中一个 tableView 单元格时,它会导航到详细 View 。这个主 TableView 是在 UITableViewController 类中创建的。 (主视图 Controller )

我使用 StoryBoard 创建主从 TableView 。

在 MasterViewController 中,当用户选择 To 按钮时,我在主 tableView 之上放置了一个 tableView。第二个 tableView 允许用户从此列表中选择多个值。

为了防止当第一个(主)tableView 滚动时第二个 tableView 在屏幕上滚动,我将第二个 tableView 添加到 MasterViewController View 的 superView。 ([self.view.superview addSubview:_toView];)

因此,在 MasterViewController 中,我添加了一个 TableViewController (_toController)。我实例化一个 UIView (_toView),向其添加背景图像 (_toViewBG),然后向其添加一个 TableView (_toTableView)。然后我将 _toView(包含第二个 tableView)添加到 MasterViewController View 的 super View 。

_toController = [[ToTableViewController alloc] init];
_toView = [[UIView alloc] initWithFrame:CGRectMake(10,10,263,247)];

_toViewBG = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,257,232)];
_toViewBG.image = [UIImage imageNamed:@"toViewBackground.png"];

[_toView addSubview:_toViewBG];

_toTableView = [[UITableView alloc] initWithFrame:CGRectMake(20,30,220,180) style:UITableViewStylePlain];

[_toTableView setDelegate:_toController];
[_toTableView setDataSource:_toController];
[_toView addSubview:_toTableView];

[self.view.superview addSubview:_toView];
[_toTableView reloadData];

当我滚动主 tableView 时,这种方法可以防止第二个 tableView 滚动。当主 tableView 滚动时,第二个 tableView 保持在顶部和原位。

如果我在主 TableView 中选择一个单元格,我将导航到详细 View 。当我返回主 TableView 时,无法显示第二个 TableView (_toView)。

我不确定如何告诉 _toView 到前面。我意识到它被添加到 MasterViewController View 的 super View 中。从一些实验来看,这个 super View 似乎是一个 CALayer。

谁能建议我如何让这个 _toView 显示在 MasterViewController View 前面?

在此先感谢您的帮助。

已解决 我最终只是将第二个 TableView 添加为 MasterViewController View 的 subview 。 [self.view addSubview:_toView]; 然后,当我的第二个 tableview 可见时,我禁用了主 tableview 上的滚动。

Self.tableView.scrollEnabled  = No;

似乎工作正常。

蒂姆

最佳答案

也许可以通过调用[self.view.superview bringSubviewToFront:_toView]来完成这项工作,但我的建议是让MasterViewController成为UIViewController 而不是 UITableViewController,然后将两个 UITableView 对象添加为 Root View 的 subview ,(而不是引用 superview)。

关于ios - 添加到 super View 的 View 在导航 TableView 时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16070305/

相关文章:

objective-c - iOS - 在没有应用程序更新的情况下更新用户流程

arraylist - 来自 List 的 javafx tableview 数据

ios - 处理URLSession时是否总是需要[Weak self]?

android - 在 Android 和 iOS 上保护 HTTP API 调用的最简单和最安全的方法是什么?

ios - 角标(Badge)号码不会清除

swift - 奇怪的TableView和SearchBar

iphone - Autolayout 不适用于可重用的 tableview 单元格

ios - 嵌入导航 Controller 而不替换背景

ios - 快速IOS联系人攻略 "friend finder"

ios - UITableView 和 AutoLayout - 没有显示表格