Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-是否可以从模式显示的视图控制器中显示模式视图控制器?_Ios_Uiimagepickercontroller_Modalviewcontroller_Presentviewcontroller - Fatal编程技术网

iOS-是否可以从模式显示的视图控制器中显示模式视图控制器?

iOS-是否可以从模式显示的视图控制器中显示模式视图控制器?,ios,uiimagepickercontroller,modalviewcontroller,presentviewcontroller,Ios,Uiimagepickercontroller,Modalviewcontroller,Presentviewcontroller,我正在开发一个显示“编辑配置文件”屏幕的应用程序。然后从这个屏幕上,我想展示另一个模态视图控制器,UIImagePickerController。但是,我无法执行此操作,并继续收到以下错误: ***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“应用程序试图显示” 模态视图控制器本身。呈现控制器是 UIImagePickerController:0x13d077000。' 在我的应用程序中,在我的个人资料屏幕上,我让右上角的栏按钮项以如下方式显示

我正在开发一个显示“编辑配置文件”屏幕的应用程序。然后从这个屏幕上,我想展示另一个模态视图控制器,UIImagePickerController。但是,我无法执行此操作,并继续收到以下错误:

***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“应用程序试图显示” 模态视图控制器本身。呈现控制器是 UIImagePickerController:0x13d077000。'

在我的应用程序中,在我的个人资料屏幕上,我让右上角的栏按钮项以如下方式显示“编辑个人资料”屏幕:

//  MyProfileViewController.m
// ...

- (void)rightBarButtonItemTapped:(id)sender
{
    EditMyProfileViewController *editMyProfileVC = [[EditMyProfileViewController alloc] init];
    editMyProfileVC.delegate = self;
    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:editMyProfileVC];
    navVC.navigationBar.translucent = NO;
    [self presentViewController:navVC animated:YES completion:^{}];
}
然后,在modally呈现的“edit profile”屏幕的上下文中,我希望能够modally呈现UIImagePickerController。我尝试这样做:

//  EditMyProfileViewController.m
// ...

#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ([actionSheet isEqual:self.profilePicActionSheet])
    {
        if (buttonIndex == 0) // Camera
        {
            [self.profilePicActionSheet dismissWithClickedButtonIndex:0 animated:YES];
            [self showPhotoPickerUsingSourceType:UIImagePickerControllerSourceTypeCamera];
        }
        if (buttonIndex == 1) // Photo Library
        {
            [self.profilePicActionSheet dismissWithClickedButtonIndex:0 animated:YES];
            [self showPhotoPickerUsingSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        }
        if (buttonIndex == 2) // Saved Photos Album
        {
            [self.profilePicActionSheet dismissWithClickedButtonIndex:0 animated:YES];
            [self showPhotoPickerUsingSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
        }
    }
}

- (void)showPhotoPickerUsingSourceType:(UIImagePickerControllerSourceType)sourceType
{
    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
    if (status != ALAuthorizationStatusAuthorized)
    {
        // ...
    }
    else // status == ALAuthorizationStatusAuthorized
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] initWithRootViewController:self];
        imagePicker.sourceType = sourceType;
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        if ([UIImagePickerController isSourceTypeAvailable:sourceType])
        {
            [self presentViewController:imagePicker animated:YES completion:^{
                NSLog(@"imagePicker is on screen..."); // <-- App crashes before we get here
            }];
        }
        else
        {
            [Helper helperShowAlertWithTitle:@"Selected Source Type Not Available"];
        }
    }
}
//EditMyProfileViewController.m
// ...
#pragma标记-UIActionSheetDelegate
-(无效)操作表:(UIActionSheet*)操作表单击按钮索引:(NSInteger)按钮索引
{
if([actionSheet isEqual:self.profilePicActionSheet])
{
如果(buttonIndex==0)//摄像机
{
[self.profilePicActionSheet Dismiss with Clicked Button索引:0动画:是];
[自显示PhotoPickerSingSourceType:UIImagePickerControllerSourceTypeCamera];
}
if(buttonIndex==1)//照片库
{
[self.profilePicActionSheet Dismiss with Clicked Button索引:0动画:是];
[自显示PhotoPickerSingSourceType:UIImagePickerController源类型PhotoLibrary];
}
if(buttonIndex==2)//保存的相册照片
{
[self.profilePicActionSheet Dismiss with Clicked Button索引:0动画:是];
[自显示PhotoPickerSingSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
}
}
}
-(void)ShowPhotoPickerSingSourceType:(UIImagePickerControllerSourceType)sourceType
{
AlaAuthorizationStatus=[ALAssetsLibrary authorizationStatus];
如果(状态!=ALAuthorizationStatusAuthorized)
{
// ...
}
else//status==ALAuthorizationStatusAuthorized
{
UIImagePickerController*ImagePickerController=[[UIImagePickerController alloc]initWithRootViewController:self];
imagePicker.sourceType=源类型;
imagePicker.delegate=self;
imagePicker.allowsEditing=是;
if([UIImagePickerController IsSourceType可用:sourceType])
{
[self-presentViewController:imagePicker已设置动画:是完成:^{
NSLog(@“imagePicker在屏幕上…”);更改

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] initWithRootViewController:self];

改变

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] initWithRootViewController:self];


当您尝试显示图像选择器时,
self
是什么?
self
是模式显示的视图控制器,
EditMyProfileViewController
EditMyProfileViewController
位于
UINavigationController
中,这就是实际显示的内容,如
RightBarButtonItemMapped中所示e> @matt I添加了更多的代码细节。希望这会有所帮助。当您尝试演示图像选择器时,
self
是什么?
self
是模式显示的视图控制器,
EditMyProfileViewController
EditMyProfileViewController
位于
UINavigationController
中,这就是实际显示的视图控制器如
rightbarbuttonimtapped
@matt中所示,我添加了更多的代码详细信息。希望这会有所帮助。捕捉良好。我没有滚动足够的时间来注意到使用了错误的初始值设定项。捕捉良好。我没有滚动足够的时间来注意到使用了错误的初始值设定项。