ios从另一个 Controller 中删除 subview

标签 ios

我从 Controller A 添加了一个 subview 。现在在 Controller B ( subview Controller )中,当用户完成 View B 时如何重新加载 View A?我添加 subview 的代码:

ChangeProfileImage *changeProfileImage =[[ChangeProfileImage alloc] init];  
    changeProfileImage.modalPresentationStyle = UIModalPresentationFormSheet;
    changeProfileImage.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    changeProfileImage.view.frame = CGRectMake(50, 50, 300, 300);  
    UIView *dimBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
    dimBackgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f];  
    [self.view addSubview:dimBackgroundView];
    [self.view addSubview:changeProfileImage.view];

最佳答案

您可以为“dimbackground”设置一个标签..并像这样删除它:

dimBackgroundView.tag = 111;//you will do this line when you create the view.
UIView *view = [controllerA.view viewWithTag:111];
[view removeFromSuperview];

刷新你的viewController:

当用户单击提交按钮并且您删除 B View 时..使用 NSNotificationCenter 发布通知,如下所示:

[[NSNotificationCenter defaultCenter] postNotificationName:@"UserSubmit" object:nil];

并在controllerA .. viewDidLoad中例如将其添加为观察者,如下所示

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView) name:@"UserSubmit" object:nil];

您将实现此功能:

- (void) refreshView
{
    //Do your stuff
}

关于ios从另一个 Controller 中删除 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10471777/

相关文章:

objective-c - 子类化您自己的类之一还是使用相同的父类?

javascript - 如何在IOS设备上离开页面之前将数据保存在本地存储中?

ios - 按钮框架在运行时变化

iphone - 如何从自身通过电子邮件发送 Iphone 应用程序的 sqlite 数据库?

ios - 导航 Controller popToRootController() 后跟推送 Controller UI 错误

ios - 从教程制作简单的 HomeKit 应用程序并在附加 HMAccessory 时出错

ios - 如果我调用 cancelAllOpeartions,OperationQueue 不会从队列中删除操作

ios - 当链接器 "Link All"在 iOS 的 MvvmCross 中启用时,方法 ViewModel.Init 接收 null 作为参数

php - 将数组从 PHP 发送到 NSURLSession

ios - 在 UIInputViewController 框架外绘图