我正在开发一个基于标签栏的简单应用程序。我正在尝试打开图像选择器,使用通用代码从库中选择一些图像,如下所示:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
[self.navigationController presentViewController:picker animated:YES completion:NULL];
但它的崩溃与非常奇怪的日志。
2015-10-18 22:42:54.959 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x79eb3c10' *** First throw call stack: ( 0 CoreFoundation 0x02b1adf6 __exceptionPreprocess + 182 1 libobjc.A.dylib 0x027a4a97 objc_exception_throw + 44 2 CoreFoundation 0x02b22a75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277 3 CoreFoundation 0x02a6b9c7 ___forwarding___ + 1047 4 CoreFoundation 0x02a6b58e _CF_forwarding_prep_0 + 14 5 UIKit 0x010c1e9f -[UISearchBar(UISearchBarStatic) _updateMagnifyingGlassView] + 490 6 UIKit 0x010c08d9 -[UISearchBar _applySearchBarStyle] + 385 7 UIKit 0x010c22e2 -[UISearchBar(UISearchBarStatic) _setupSearchField] + 1065 8 UIKit 0x010b7da2 -[UISearchBar searchField] + 48 9 PhotosUI 0x11bfd271 +[PUSearchViewController(PresentationHelpers) newSearchBar] + 103 10 PhotosUI 0x11b807fb -[PUSearchButtonItem initWithNavigationItem:target:action:] + 477 11 PhotosUI 0x11a4476b -[PUPhotosGridViewController searchButtonItem] + 130 12 PhotosUI 0x11a48520 -[PUPhotosGridViewController updateNavigationBarAnimated:] + 458 13 PhotosUI 0x11a472ed -[PUPhotosGridViewController updatePeripheralInterfaceAnimated:] + 110 14 PhotosUI 0x11a4a3b4 -[PUPhotosGridViewController updateInterfaceForModelReloadAnimated:] + 267 15 PhotosUI 0x11a3fe46 -[PUPhotosGridViewController viewWillAppear:] + 361 16 UIKit 0x00ebd14f -[UIViewController _setViewAppearState:isAnimating:] + 545 17 UIKit 0x00ebd6ca -[UIViewController __viewWillAppear:] + 148 18 UIKit 0x014a0e0f -[UICollectionViewController __viewWillAppear:] + 59 19 UIKit 0x00eef389 -[UINavigationController _startTransition:fromViewController:toViewController:] + 931 20 UIKit 0x00eeffdb -[UINavigationController _startDeferredTransitionIfNeeded:] + 669 21 UIKit 0x00ee05ca -[UINavigationController _setViewControllers_7_0:transition:animated:operation:] + 2983 22 UIKit 0x00edf70b -[UINavigationController _setViewControllers:transition:animated:operation:] + 476 23 UIKit 0x00edf9a2 -[UINavigationController _setViewControllers:transition:animated:] + 65 24 UIKit 0x00ede9f3 __54-[UINavigationController setViewControllers:animated:]_block_invoke + 1277 25 UIKit 0x00edea82 __54-[UINavigationController setViewControllers:animated:]_block_invoke298 + 33 26 UIKit 0x00ec515d +[UIViewController _performWithoutDeferringTransitions:] + 107 27 UIKit 0x00ede4d2 -[UINavigationController setViewControllers:animated:] + 549 28 UIKit 0x01066c0c -[UIImagePickerController _setupControllersForCurrentSourceType] + 187 29 UIKit 0x01066159 -[UIImagePickerController viewWillAppear:] + 62 30 UIKit 0x00ebd14f -[UIViewController _setViewAppearState:isAnimating:] + 545 31 UIKit 0x00ebd6ca -[UIViewController __viewWillAppear:] + 148 32 UIKit 0x00ed50b1 -[UIViewController(UIContainerViewControllerProtectedMethods) beginAppearanceTransition:animated:] + 200 33 UIKit 0x00e91784 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 786 34 UIKit 0x00ec521b __40+[UIViewController _scheduleTransition:]_block_invoke + 18 35 UIKit 0x00d8b62e ___afterCACommitHandler_block_invoke + 15 36 UIKit 0x00d8b5d9 _applyBlockToCFArrayCopiedToStack + 415 37 UIKit 0x00d8b3ee _afterCACommitHandler + 545 38 CoreFoundation 0x02a3dfbe __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 39 CoreFoundation 0x02a3df00 __CFRunLoopDoObservers + 400 40 CoreFoundation 0x02a3393a __CFRunLoopRun + 1226 41 CoreFoundation 0x02a331ab CFRunLoopRunSpecific + 443 42 CoreFoundation 0x02a32fdb CFRunLoopRunInMode + 123 43 GraphicsServices 0x051d624f GSEventRunModal + 192 44 GraphicsServices 0x051d608c GSEventRun + 104 45 UIKit 0x00d61e16 UIApplicationMain + 1526 46 CrimeChat 0x0014311d main + 141 47 libdyld.dylib 0x03470ac9 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
我想添加一个相同代码在其他项目中工作的东西。我尝试过不同的项目。