2

在我的应用程序中,我用相机拍照后,我想导航到另一个视图控制器

didFinishPickingMediaWithInfo

现在,我正在dismissViewControllerAnimated 函数的完成块中执行此操作,但我觉得这不是最优雅的方式。你能告诉我如何才能做得更好吗?这是确切的代码

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *mediaType = info[UIImagePickerControllerMediaType];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *image = [info[UIImagePickerControllerOriginalImage] scaledCopyOfSize:CGSizeMake(175.0f, 175.0f)];


        [self dismissViewControllerAnimated:YES completion:^(void){
            setVC = [[SetVCr alloc]init];

            [[self navigationController]pushViewController:seVC animated:YES];
        }];   
    }   
}
4

2 回答 2

1

您可以直接从选择器推送新的视图控制器

  - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        NSString *mediaType = info[UIImagePickerControllerMediaType];

        if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
            UIImage *image = [info[UIImagePickerControllerOriginalImage]  scaledCopyOfSize:CGSizeMake(175.0f, 175.0f)];
            setVC = [[SetVCr alloc]init];
           [picker pushViewController:seVC animated:YES];//you can push new view controller directly from the picker
        }   
    }
于 2013-04-16T10:15:56.467 回答
0

I suggest setting your completion block to nil and on the next line call the 'performSegueWithIdentifier' method as written below:

[self performSegueWithIdentifier:@"segueToNewcontroller" sender:self];
于 2015-11-24T17:46:38.040 回答