gpt4 book ai didi

ios - 从 UIWindow 中移除 UIViewController 的 View

转载 作者:行者123 更新时间:2023-11-28 18:29:14 28 4
gpt4 key购买 nike

当用户单击添加按钮时,我将在 UIWindow 上添加 View 。现在,如果用户再次点击添加按钮,我想先删除该 View 并再次添加。

我已使用此代码在 UIWindow 上添加 View :

ProgressVC *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"IDProgressVC"];
[[[[UIApplication sharedApplication] delegate]window] addSubview:vc.view];

对于删除,我已经尝试过此代码:

[vc.view removeFromSuperview];
[[[[UIApplication sharedApplication] delegate]window] setNeedsLayout];
vc = nil;

我们将不胜感激。

最佳答案

试试这个

// Make this global property

@property(nonatomic, strong) UIView * currentView;

//store the view in gloabal property
ProgressVC *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"IDProgressVC"];
currentView = vc.view;
[[[[UIApplication sharedApplication] delegate]window] addSubview:currentView];

//remove it
[currentView removeFromSuperview];
[[[[UIApplication sharedApplication] delegate]window] setNeedsLayout];
currentView = nil;

关于ios - 从 UIWindow 中移除 UIViewController 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38100956/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com