OGeek|极客世界-中国程序员成长平台

标题: ios - 通过代码将 subview 添加到 View 重新加载后消失 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 20:04
标题: ios - 通过代码将 subview 添加到 View 重新加载后消失

我正在尝试通过代码将 UI 组件添加到我的 View 中,它运行良好,直到我返回 View (通过弹出 View 功能)我发现通过 Interface builder 添加的组件仍然存在,而通过添加的组件代码被删除! (我试图在 VC 中打印 subview ,但它们不存在)。

我错过了什么??

SharedDataObject.m

@property (retain, nonatomic) UIImageView *brandLogoImageView;
@property (retain, nonatomic) UILabel *brandNameLabel;

ViewController.m

- (void)initUI {
    if ([[SharedDataObject shared]noLogo]) {
        [[[self view] viewWithTag:13]addSubview:[[SharedDataObject shared] brandNameLabel]];
    }
    else
    {
        [[[self view] viewWithTag:13]addSubview:[[SharedDataObject shared] brandLogoImageView]];
    }

    [_brandMessageLabel setText:[[[SharedDataObject shared] loginObject] promotion]];
}

- (void)viewDidLoad {
    [self initUI];
}



Best Answer-推荐答案


我猜你正在使用这个 View [[SharedDataObject shared]brandLogoImageView] 在您推送的 View Controller 中。

UIKit 框架只允许每个 View 有一个 super View 。所以你需要重新添加或使用另一个imageview来在两个viewcontrollers中显示图像。

关于ios - 通过代码将 subview 添加到 View 重新加载后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271222/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4