首页 文章

在导航tableview时添加到superview的视图消失了

提问于
浏览
1

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

我使用StoryBoard创建了主要细节表视图 .

在MasterViewController中,当用户选择To按钮时,我在主tableView的顶部放置一个tableView . 第二个tableView允许用户从此列表中选择多个值 .

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

所以,在MasterViewController中,我添加了一个TableViewController(_toController) . 我实例化一个UIView(_toView),向它添加一个背景图像(_toViewBG),然后向它添加一个TableView(_toTableView) . 然后我将_toView(包含第二个tableView)添加到MasterViewController视图的superview .

_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中选择一个单元格,我会导航到详细视图 . 当我返回主TableView时,我无法显示第二个TableView(_toView) .

我不知道如何告诉_toView来到前面 . 我意识到它被添加到MasterViewController视图的superview中 . 从一些实验来看,这个超级视图似乎是一个CALayer .

任何人都可以建议我如何让这个_toView显示在MasterViewController视图的前面?

在此先感谢您的任何帮助 .

Solved 我最后只是将第二个tableview添加为MasterViewController视图的子视图 . [self.view addSubview:_toView];然后我在主桌面视图上禁用滚动,同时我的第二个桌面视图可见 .

Self.tableView.scrollEnabled  = No;

似乎工作正常 .

蒂姆

1 回答

  • 1

    有可能通过调用 [self.view.superview bringSubviewToFront:_toView] 来完成这项工作,但我的建议是使 MasterViewController 成为 UIViewController 的子类而不是 UITableViewController ,然后将两个 UITableView 对象添加为根视图的子视图,(而不是引用 superview ) .

相关问题