在我的UINavigationController
视图之一中,用户可以按“添加”按钮以使用UIImagePickerController
从相册中选择照片。当用户选择所需的照片时,我想将他移动到AddPhotoViewController
视图,在其中他可以添加标题和说明,而不是可以按“保存”按钮保存数据,关闭AddPhotoViewController
视图并返回到上一个UINavigationController
视图。到目前为止,我只能推送AddPhotoViewController
视图,而不能将其作为模式视图。这就是我这样做的方式:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
AddPhotoViewController *apvc = [self.storyboard instantiateViewControllerWithIdentifier:@"addPhoto"];
apvc.info = info;
[self.navigationController pushViewController:apvc animated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
上面的代码工作正常,但是我想将AddPhotoViewController添加为模式视图。我想使用
presentModalViewController:animated:
,但是在iOS 6.0中已弃用。比我尝试过的: [self presentViewController:apvc animated:YES completion:nil];
代替:
[self.navigationController pushViewController:apvc animated:YES];
但我收到此错误:
Warning: Attempt to present <AddPhotoViewController: 0x1e183fc0> on <UINavigationController: 0x1d594a70> whose view is not in the window hierarchy!
关闭
UINavigationController
视图后,是否可以在UIImagePickerController
视图顶部添加模式视图? 最佳答案
得益于轻松的搜索功能,您可以获得想要的导航。
在您的第一个viewController中,实现一个放松的搜索
- (IBAction)unwindSegue:(UIStoryboardSegue*)segue
{
NSLog (@"unwound");
//you can extract data from your "addPhoto" viewController here
//via segue.sourceViewController
}
确保在头文件中声明它。
在您的“addPhoto” viewController中,添加某种关闭按钮,然后将CTRL拖动到控制器底部的“退出”符号上。放松的选择应该是可选的。
要获取
addPhoto
,可以模态呈现-但要求imagePickerController进行呈现:- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIViewController* addPhotoController =
[self.storyboard instantiateViewControllerWithIdentifier:@"addPhoto"];
addPhotoController.infoDict = info; //passing the image data to addPhoto
[picker presentViewController:addPhotoController
animated:YES
completion:nil];
}
因此,您确实得到了两层演示,但是在每种情况下,都是由前一个控制器进行演示。不要解雇imagePickerController。执行解散命令时,它将为您进行解雇。