我从控制器A添加了一个子视图。现在在作为子视图控制器的控制器B中,如何在用户完成B时重新加载视图A.我添加子视图的代码:
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];
答案 0 :(得分:1)
你可以为“dimbackground”设置一个标签..并将其删除如下:
dimBackgroundView.tag = 111;//you will do this line when you create the view.
UIView *view = [controllerA.view viewWithTag:111];
[view removeFromSuperview];
刷新viewController:
当用户点击提交按钮并删除B视图时..使用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
}
答案 1 :(得分:0)
在视图控制器B上创建一个按钮,IBAction连接到它,在该按钮的IBaction中写下面的代码,这将删除viewcontroller B
[self.view removeFromSuperview];