如何弹出UIImagePickerController的导航

时间:2013-12-21 02:20:38

标签: ios objective-c ios7 uiimagepickercontroller

我正在从照片库中选择一张照片,然后使用两个按钮创建自定义叠加/裁剪视图:取消和选择。取消应弹出到上一个视图以返回到照片库以选择其他图像。

我正在试图弄清楚如何获得UIImagePickerController的导航回目标,但它一直在崩溃我。

感谢您的回复。

以下是我正在使用的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    UIViewController *cropController = [[UIViewController alloc]init];

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    UIView *cropView = [[UIView alloc]initWithFrame:CGRectMake(0,0,screenWidth,screenHeight)];

    UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 50)];
    [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
    [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelButton setTitleColor:[UIColor colorWithRed:(16.0/255.0) green:(100.0/255.0) blue:(230.0/255.0) alpha:1.0] forState:UIControlStateHighlighted];

    [cancelButton addTarget:self action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];

    UIButton *chooseButton = [[UIButton alloc]initWithFrame:CGRectMake(250, 0, 70, 50)];
    [chooseButton setTitle:@"Choose" forState:UIControlStateNormal];
    [chooseButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [chooseButton setTitleColor:[UIColor colorWithRed:(16.0/255.0) green:(100.0/255.0) blue:(230.0/255.0) alpha:1.0] forState:UIControlStateHighlighted];

    UIView *buttonsView = [[UIView alloc]initWithFrame:CGRectMake(0, 518, 320, 50)];

    [buttonsView addSubview:chooseButton];
    [buttonsView addSubview:cancelButton];

    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:cropView.frame];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:originalImage];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.frame = scrollView.bounds;

    scrollView.backgroundColor = [UIColor blackColor];
    scrollView.minimumZoomScale = 1.0  ;
    scrollView.maximumZoomScale = imageView.image.size.width / scrollView.frame.size.width;
    scrollView.zoomScale = 1.0;
    scrollView.contentSize = imageView.image.size;
    scrollView.delegate = self;

    [scrollView addSubview:imageView];

    [cropView addSubview:scrollView];

    [cropView addSubview:buttonsView];

    cropController.view = cropView;

    [picker pushViewController:cropController animated:YES];

}

编辑:崩溃日志:

2013-12-20 21:28:39.009 [15197:70b] -[SettingsTableViewController popViewControllerAnimated:]: unrecognized selector sent to instance 0x1095cff0
2013-12-20 21:28:39.012 [15197:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SettingsTableViewController popViewControllerAnimated:]: unrecognized selector sent to instance 0x1095cff0'
*** First throw call stack:
(
    0   CoreFoundation                      0x01ab45e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0175d8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01b51903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x01aa490b ___forwarding___ + 1019
    4   CoreFoundation                      0x01aa44ee _CF_forwarding_prep_0 + 14
    5   libobjc.A.dylib                     0x0176f874 -[NSObject performSelector:withObject:withObject:] + 77
    6   UIKit                               0x004cd0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
    7   UIKit                               0x004cd04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    8   UIKit                               0x005c50c1 -[UIControl sendAction:to:forEvent:] + 66
    9   UIKit                               0x005c5484 -[UIControl _sendActionsForEvents:withEvent:] + 577
    10  UIKit                               0x005c4733 -[UIControl touchesEnded:withEvent:] + 641
    11  UIKit                               0x0050a51d -[UIWindow _sendTouchesForEvent:] + 852
    12  UIKit                               0x0050b184 -[UIWindow sendEvent:] + 1232
    13  UIKit                               0x004dee86 -[UIApplication sendEvent:] + 242
    14  UIKit                               0x004c918f _UIApplicationHandleEventQueue + 11421
    15  CoreFoundation                      0x01a3d83f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    16  CoreFoundation                      0x01a3d1cb __CFRunLoopDoSources0 + 235
    17  CoreFoundation                      0x01a5a29e __CFRunLoopRun + 910
    18  CoreFoundation                      0x01a59ac3 CFRunLoopRunSpecific + 467
    19  CoreFoundation                      0x01a598db CFRunLoopRunInMode + 123
    20  GraphicsServices                    0x02d7a9e2 GSEventRunModal + 192
    21  GraphicsServices                    0x02d7a809 GSEventRun + 104
    22  UIKit                               0x004cbd3b UIApplicationMain + 1225
    23  App                            0x00012872 main + 178
    24  libdyld.dylib                       0x0638370d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

2 个答案:

答案 0 :(得分:1)

UIImagePickerController(您显示的代码中的picker UINavigationController。您希望弹出消息转到它(picker),而不是self。您的self不是UINavigationController,因此当弹出消息发送给它时,您自然会崩溃。

答案 1 :(得分:1)

请参阅matt的回答

替换此

[picker pushViewController:cropController animated:YES];

[self.navigationController pushViewController:cropController animated:YES];