【问题标题】:UI in Container View is not updating容器视图中的 UI 未更新
【发布时间】:2016-10-10 16:07:00
【问题描述】:

我有一个带有按钮的视图,当用户按下按钮时,会显示一个容器视图。我用:

ContainerView.setNeedsDisplay()

更新容器视图。我这样做是因为我有诸如标签之类的 UI,并且我希望文本基于单击的按钮。

问题在于,在更新视图和更新文本时,标签文本不会改变。

【问题讨论】:

标签: ios swift user-interface uilabel uicontainerview


【解决方案1】:

感谢 Rroobb 的评论,这很有效! - stackoverflow.com/a/37748737/3108877

【讨论】:

    【解决方案2】:

    我写了一个助手来做这个,源代码可以帮助你:

    + (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];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-17
      • 2018-06-26
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多