我从 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/