简体   繁体   English

容器视图中的用户界面未更新

[英]UI in Container View is not updating

I have a view with buttons, when the user presses the button a container view is displayed. 我有一个带有按钮的视图,当用户按下按钮时,将显示一个容器视图。 I use: 我用:

ContainerView.setNeedsDisplay()

to update the container view. 更新容器视图。 I do this because I have UI such as a label and I want the text to be based on what button is clicked. 之所以这样做,是因为我拥有UI(例如标签),并且希望文本基于单击的按钮。

The issue is that whilst the view is being updated, and the text is being updated, the label text does not change. 问题在于,在更新视图和更新文本的同时,标签文本不会更改。

Thanks Rroobb for your comment, that works! 感谢Rroobb的评论,这行得通! - stackoverflow.com/a/37748737/3108877 -stackoverflow.com/a/37748737/3108877

I wrote a Helper that does just this, source may help you: 我写了一个Helper来做到这一点,来源可能会帮助您:

+ (void)navigateFromController:(UIViewController *)fromController toController:(UIViewController *)toController {
    if (fromController) {
        // Remove any existing child controllers.
        for (UIViewController *child in [toController childViewControllers]) {
            [child willMoveToParentViewController:nil];
            [child.view removeFromSuperview];
            [child removeFromParentViewController];
        }

        // Embed the new controller.
        [fromController addChildViewController:toController];

        toController.view.frame = fromController.view.bounds;
        toController.view.translatesAutoresizingMaskIntoConstraints = false;
        [fromController.view addSubview:toController.view];

        [toController.view.leftAnchor constraintEqualToAnchor:fromController.view.leftAnchor].active = YES;
        [toController.view.rightAnchor constraintEqualToAnchor:fromController.view.rightAnchor].active = YES;
        [toController.view.topAnchor constraintEqualToAnchor:fromController.view.topAnchor].active = YES;
        [toController.view.bottomAnchor constraintEqualToAnchor:fromController.view.bottomAnchor].active = YES;

        [fromController didMoveToParentViewController:fromController];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM