我在我的应用程序(inventoryviewcontroller)中实现了相机功能。
拍摄照片后,在invetoryviewcontroller上添加了图像,但是sectionviewcontroller消失了。似乎创建了一个导航堆栈并在sectionviewcontroller的顶部添加了inventoryviewcontroller。
点击提交按钮后,inventoryviewcontroller消失,出现了sectionviewcontroller。
我在我的设备上使用ios 8操作系统。
我怎么能解决这个问题?
// 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];
}
拍摄照片之前:
拍摄完图像后:
答案 0 :(得分:1)
当将其视图添加到SectionViewController视图时,问题原因是没有将InventoryViewController添加为子视图控制器。所以这样做的代码就是这样,
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];
删除视图时,也应删除子项(此代码在子项中),
- (IBAction)submitBtn:(id)sender {
[self.view removeFromSuperview];
[self willMoveToParentViewController:nil];
[self removeFromParentViewController];
}