UITableView 在同一个 ViewController 中转场 [英] UITableView segue within the same ViewController

查看:23
本文介绍了UITableView 在同一个 ViewController 中转场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIViewController,其中包含连接在一起的地图和 tableView,它看起来像这样:

I have a UIViewController that contains both, a map and a tableView which are connected together and it looks something like this:

而且我希望能够将 tableView 推送到同一视图控制器中的另一个 tableView,以便地图保持在原处.当然,我希望能够使用将出现在左上角导航栏中的按钮以编程方式向后展开转场.

And I'd like to be able to push the tableView to another tableView within the same view controller so that the map stays where is it. Of course I'd like to be able to unwind the segue backwards programmatically with a button that'll appear in the navbaritem in the top left.

在放置在弹出窗口中的 iPad tableView 控制器中可以观察到类似的行为.我将如何在 Swift (iOS 8) 中执行此操作?

Similar behaviour can be observed in the iPad tableView controllers placed in a popover. How would I go about doing this in Swift (iOS 8) ?

非常感谢任何代码片段或指向现有代码示例的指针.

Any code snippets or pointers to existing code examples are greatly appreciated.

推荐答案

您可以像这样实现视图控制器包含:

You can achieve view controller containment like so:

- (void)viewDidLoad {
        [super viewDidLoad];

        // Setup the container view
        _containerView = [[UIView alloc] initWithFrame: // DESIRED FRAME];
        _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [self.view addSubview:_containerView];

        // Setup the main view controller
        [self addChildViewController:_mainViewController];
        _mainViewController.view.frame = _containerView.bounds;
        [_containerView addSubview:_mainViewController.view];
        [_mainViewController didMoveToParentViewController:self];
}

现在您可以在单独的视图控制器中创建两个表视图.听起来您应该向主视图控制器添加一个导航控制器(代码片段中的mainViewController"),以便您可以将新表推送"到堆栈中.

Now you can create both table views in separate view controllers. It sounds like you should add a navigation controller ("mainViewController" in code snippet) to your main view controller so you can "push" a new table onto the stack.

这篇关于UITableView 在同一个 ViewController 中转场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆