I have a UIViewController that contains a button. When I press the button I add a child view controller using the following.
- (IBAction)loadEditScreen:(id)sender {
self.editViewController = [[EditViewController alloc] init];
[self addChildViewController:self.editViewController];
[self.editViewController didMoveToParentViewController:self];
self.editViewController.view.alpha = 0;
[self.editViewController.view setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:self.editViewController.view];
[self.editViewController setupImage:self.selectedImageView.image];
[UIView animateWithDuration:0.2
delay:0.0
options:0
animations:^{
self.editViewController.view.alpha = 1;
}
completion:^(BOOL finished){}];
}
- (void)closeEditScreen {
[self.editViewController willMoveToParentViewController:nil];
[self.editViewController.view removeFromSuperview];
[self.editViewController removeFromParentViewController ];
}
Now the problem seems to be that I am not sure how to go about removing the child view controller when needed. Within the child controller I have a button that calls the following.
- (IBAction)closeEditScreen:(id)sender {
HomeViewController *tmpController = [[HomeViewController alloc] init];
[tmpController closeEditScreen];
/*[UIView animateWithDuration:0.2
delay:0.0
options:0
animations:^{
self.view.alpha = 0;
}
completion:^(BOOL finished){
[self didMoveToParentViewController:nil];
[self.view removeFromSuperview];
}];*/
}
The problem seems to be that the method gets called but nothing actually happens. The View isn't removed even though I know that method is working because I have set breakpoints.
Any help would be great. I just want to add a childviewcontroller and then have a button in the child that removes the childviewcontroller when pressed.
Thanks in Advance