2013-12-21 36 views
0

我從照片庫中選擇一張照片,然後使用兩個按鈕創建自定義疊加/裁切視圖:取消和選擇。取消應彈出到以前的視圖回到照片庫選擇一個不同的圖像。如何彈出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 
+0

可以表現出一定的崩潰日誌? – chancyWu

+0

編輯我的文章 – klcjr89

+0

上面您發送popViewControllerAnimated消息到一個SettingsTableViewController對象,它無法響應它。你在哪裏打電話? – chancyWu

回答

1

參考馬特的答案

替換此

[picker pushViewController:cropController animated:YES]; 

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

的的UIImagePickerController(picker在你展示的代碼)的UINavigationController的。你想要流行消息去(picker),而不是self。你的self不是一個UINavigationController,所以當你發送彈出消息時,你自然會崩潰。

相關問題