Ios 如何更改容器';你对UIButton满意吗?

Ios 如何更改容器';你对UIButton满意吗?,ios,objective-c,Ios,Objective C,我正在尝试将容器中的嵌入内容从tableviewcontroller更改为地图。我已经尝试过搜索它,但是所有的问题都与tabview有关,而我没有这样做。我如何开始这个过程 我也试过了 - (IBAction)changer:(id)sender { UIViewController *viewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"vc1"]; container.view

我正在尝试将容器中的嵌入内容从tableviewcontroller更改为地图。我已经尝试过搜索它,但是所有的问题都与tabview有关,而我没有这样做。我如何开始这个过程

我也试过了

- (IBAction)changer:(id)sender {
    UIViewController *viewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"vc1"];
    container.view = viewController1;
}
但这不起作用

试试看

MyViewController *viewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"vc1"];
viewController1.view.frame = self.container.bounds;

[viewController1 willMoveToParentViewController:self];
[self.container addSubview:viewController1.view];
[self addChildViewController:viewController1];
[viewController1 didMoveToParentViewController:self];

这是我在Swift中的实现:

func navigateTo(vc: NSViewController){
    vc.view.frame = self.containerView.bounds;
    if let currentSubview = containerView.subviews.first {
        self.containerView.replaceSubview(currentSubview, with: vc.view)
    } else {
        self.containerView.addSubview(vc.view)
    }
    self.addChildViewController( vc )
}
对于动画转换,我实现了awakeFromNib

override func awakeFromNib() {
    let animation: CATransition = CATransition()
    animation.type = kCATransitionMoveIn
    animation.subtype = kCATransitionFromRight
    animation.duration = 0.75
    animation.delegate = self
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    if let _ = containerView {
        containerView.wantsLayer = true
        containerView.animations = NSDictionary(object: animation, forKey: "subviews") as! [String : AnyObject]
    }
}
并将行self.containerView.replaceSubview替换为:


是否要将viewController安装到容器视图中?好的,我可以发现至少有3个问题。是的,我希望嵌入容器中的uitableviewcontroller切换到viewController does似乎不起作用:容器不切换内容。谢谢though@Alexyuiop检查viewController是否正确实例化,storyboardID是否正确,containerView是否正确连接etc@Anupdas正确连接containerView意味着什么?如果你在IB中创建它,你需要做的不仅仅是将它拖到VC中吗?@mkc842 OP没有使用故事板中提供的ContainerView,而是一个常规视图,他将viewController作为子视图添加到该视图中。我指的是,如果IBOutlet连接到该视图:)@Anupdas很酷,谢谢,多亏了你的代码,我现在可以正常工作了。但我还是想知道,通知孩子VC它将转移到父母那里,然后告诉孩子它确实这样做了,目的是什么?
self.containerView.animator().replaceSubview(currentSubview, with: vc.view)