【问题标题】:How to pop UIImagePickerController's navigation如何弹出 UIImagePickerController 的导航
【发布时间】:2013-12-21 13:30:39
【问题描述】:

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

我试图弄清楚如何到达 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

【问题讨论】:

  • 你能显示一些崩溃日志吗?
  • 您将 popViewControllerAnimated 消息发送到 SettingsTableViewController 对象,该对象无法响应。你怎么称呼它?
  • 我只是想弄清楚如何获得呈现的 uiimagepicker 控制器的导航目标,但不知道如何。
  • 推动选择器而不是呈现它的任何具体原因?

标签: ios objective-c ios7 uiimagepickercontroller


【解决方案1】:

参考马特的回答

替换这个

[picker pushViewController:cropController animated:YES];

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      相关资源
      最近更新 更多