使用UIImagePickerController访问照片库后崩溃

3

当点击按钮时,我无法访问照片库。像往常一样,我想知道是否可访问。以下是我的代码:

@IBAction func photoLibraryButtonTapped(sender: UIButton) {

        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
            imagePicker.allowsEditing = true
            self.presentViewController(imagePicker, animated: true, completion: nil)
        }
    }

以下是Xcode的内容:

2016-08-08 23:05:11.209 Auyrma[1799:20237892] -[UIViewController photoLibraryButtonTapped:]: unrecognized selector sent to instance 0x7fd3e9d39ed0
2016-08-08 23:05:11.214 Auyrma[1799:20237892] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController photoLibraryButtonTapped:]: unrecognized selector sent to instance 0x7fd3e9d39ed0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000113fdcd85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000113a50deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000113fe5d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000113f2bcfa ___forwarding___ + 970
    4   CoreFoundation                      0x0000000113f2b8a8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x00000001124d6a8d -[UIApplication sendAction:to:from:forEvent:] + 92
    6   UIKit                               0x0000000112649e67 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x000000011264a143 -[UIControl _sendActionsForEvents:withEvent:] + 327
    8   UIKit                               0x0000000112649263 -[UIControl touchesEnded:withEvent:] + 601
    9   UIKit                               0x000000011254999f -[UIWindow _sendTouchesForEvent:] + 835
    10  UIKit                               0x000000011254a6d4 -[UIWindow sendEvent:] + 865
    11  UIKit                               0x00000001124f5dc6 -[UIApplication sendEvent:] + 263
    12  UIKit                               0x00000001124cf553 _UIApplicationHandleEventQueue + 6660
    13  CoreFoundation                      0x0000000113f02301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x0000000113ef822c __CFRunLoopDoSources0 + 556
    15  CoreFoundation                      0x0000000113ef76e3 __CFRunLoopRun + 867
    16  CoreFoundation                      0x0000000113ef70f8 CFRunLoopRunSpecific + 488
    17  GraphicsServices                    0x00000001164bcad2 GSEventRunModal + 161
    18  UIKit                               0x00000001124d4f09 UIApplicationMain + 171
    19  Auyrma                              0x000000010e1c2d82 main + 114
    20  libdyld.dylib                       0x0000000114e8492d start + 1
    21  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

你检查过IBAction是否正确连接到按钮了吗?或者你在哪里调用photoLibraryButtonTapped方法? - Teja Nandamuri
@teja 是的,已经仔细检查过了。一切都没问题。 - Anuar Maratkhan
你在IB中设置了你的UIViewController类吗? - Adil Soomro
@adil 是的,我也进行了双重检查。 - Anuar Maratkhan
@teja 类名是ChallengeViewController,一切都没问题,因为当我打开助手编辑器时它显示了正确的类。这个类是一个cocoa touch类,它是UIViewController。 - Anuar Maratkhan
显示剩余4条评论
2个回答

7

1.请确保您的视图控制器和故事板文件的目标在同一个目标中。 2.选择您的xib并删除映射到该故事板的类,然后重新映射并按下enter键,一旦您粘贴了类,您的nib名称保持不变以进行测试。 3.如果此按钮正在从自定义视图加载到视图控制器,则需要检查将自定义视图添加到正确的目标,并再次重新映射touch up inside与ibaction。

这是我根据您的对话所能理解的内容。


0

我是这样解决我的问题的:

  1. 打开“工具”
  2. 打开“身份检查器”
  3. 重新提供类名(但它已经存在)

看起来这是 Xcode 的一个 bug…


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接