我有按钮视图,当用户按下按钮时,会显示容器视图。我用:
ContainerView.setNeedsDisplay()
更新容器视图。我这样做是因为我有一个标签等UI,我希望文本基于点击的按钮。
问题在于,在更新视图并更新文本时,标签文本不会更改。
答案 0 :(得分:1)
感谢Rroobb的评论,这很有效! - stackoverflow.com/a/37748737/3108877
答案 1 :(得分:0)
我写了一个帮助你的帮手,来源可以帮到你:
+ (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];
}
}