【问题标题】:Unrecognized selector sent to instance with FIRAuth使用 FIRAuth 将无法识别的选择器发送到实例
【发布时间】:2017-02-07 22:57:02
【问题描述】:

我收到以下错误

2017-02-07 23:50:44.987 Eat and Write[43621:3732723] -[UIViewController logOutAction:]: unrecognized selector sent to instance 0x7fa7a4c379c0
2017-02-07 23:50:44.991 Eat and Write[43621:3732723] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController logOutAction:]: unrecognized selector sent to instance 0x7fa7a4c379c0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000103beed4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010322f21e objc_exception_throw + 48
    2   CoreFoundation                      0x0000000103c5ef04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x0000000103b74005 ___forwarding___ + 1013
    4   CoreFoundation                      0x0000000103b73b88 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000104ad28bc -[UIApplication sendAction:to:from:forEvent:] + 83
    6   UIKit                               0x0000000104c58c38 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x0000000104c58f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
    8   UIKit                               0x0000000104c57e4d -[UIControl touchesEnded:withEvent:] + 668
    9   UIKit                               0x0000000104b40545 -[UIWindow _sendTouchesForEvent:] + 2747
    10  UIKit                               0x0000000104b41c33 -[UIWindow sendEvent:] + 4011
    11  UIKit                               0x0000000104aee9ab -[UIApplication sendEvent:] + 371
    12  UIKit                               0x00000001052db72d __dispatchPreprocessedEventFromEventQueue + 3248
    13  UIKit                               0x00000001052d4463 __handleEventQueue + 4879
    14  CoreFoundation                      0x0000000103b93761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x0000000103b7898c __CFRunLoopDoSources0 + 556
    16  CoreFoundation                      0x0000000103b77e76 __CFRunLoopRun + 918
    17  CoreFoundation                      0x0000000103b77884 CFRunLoopRunSpecific + 420
    18  GraphicsServices                    0x0000000107f8ba6f GSEventRunModal + 161
    19  UIKit                               0x0000000104ad0c68 UIApplicationMain + 159
    20  Eat and Write                       0x00000001021e750f main + 111
    21  libdyld.dylib                       0x0000000106d7568d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

这个代码似乎是问题

@IBAction func logOutAction(_ sender: Any) {

    try! FIRAuth.auth()!.signOut()

    if FIRAuth.auth()!.currentUser != nil { // <-- scheint zu buggen
        do {
            try! FIRAuth.auth()!.signOut()
            let vc = UIStoryboard(name: "AuthScreen", bundle: nil).instantiateViewController(withIdentifier: "SignUp")
            self.present(vc, animated: true, completion: nil)


        } catch let error as NSError {
            print(error.localizedDescription)
        }
    }
}

登录和 FIRAuth.auth() 中的其他内容都可以正常工作。我也可以轻松地在故事板之间“跳转”。我不知道问题出在哪里。

编辑: 我感觉错误出现在

try! FIRAuth.auth()!.signOut()

编辑 2: 创建一个新的 ViewController 修复了它,我使用的那个是错误的,找不到导致错误的原因

【问题讨论】:

  • 你同时有两个故事板?
  • 您的实例化视图控制器似乎无法从系统端识别。将以下代码行添加到您的 vc 中: let vc = UIStoryboard(name: "AuthScreen", bundle: nil).instantiateViewController(withIdentifier: "SignUp") as! YourViewControllerForSignUP
  • @Mannopson 是的,一个是我的授权故事板(登录/注册/密码重置),另一个是主应用程序
  • 您是否按照上面的建议更改了代码?
  • @Mannopson 我刚起床以后试试看,有没有用再回复

标签: ios swift firebase firebase-authentication


【解决方案1】:

(代表 OP 发布)

已解决:该类是 WriteUITest 的一部分,而不是应用程序本身。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-28
    • 2012-07-24
    相关资源
    最近更新 更多