Reputation: 16813
I have implemented camera feature into my application (inventoryviewcontroller).
After I take picture, then image is added on invetoryviewcontroller but sectionviewcontroller disappears. It seems that creates a navigation stack and adding inventoryviewcontroller on the top of sectionviewcontroller.
Once I click on submit button, inventoryviewcontroller disappears and sectionviewcontroller appears.
I am using ios 8 operating system on my device.
How could I able to fix that problem?
// SectionViewController.m
iViewController = (InventoryViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"InventoryViewController"];
iViewController.view.frame = CGRectMake(728, 32, 300, 736);
[self.view addSubview:iViewController.view];
iViewController.view.tag = 17;
// InventoryVieController.m
- (IBAction)cameraBtn:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.noteImageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (IBAction)submitBtn:(id)sender {
UIView *viewToRemove = [self.view viewWithTag:17];
[viewToRemove removeFromSuperview];
}
Before image is taken:
After image is taken :
Upvotes: 0
Views: 46
Reputation: 104082
The problem turns out to be not adding the InventoryViewController as a child view controller, when its view is added to SectionViewController's view. So the code to do that looks like this,
iViewController = (InventoryViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"InventoryViewController"];
[self addChildViewController: iViewController];
[iViewController didMoveToParentViewController: self];
iViewController.view.frame = CGRectMake(728, 32, 300, 736);
[self.view addSubview:iViewController.view];
When removing the view, the child should also be removed (this code is in the child),
- (IBAction)submitBtn:(id)sender {
[self.view removeFromSuperview];
[self willMoveToParentViewController:nil];
[self removeFromParentViewController];
}
Upvotes: 1