我遇到了最令人沮丧的错误。我正在我的应用程序中设置通知并使用 swift 4.2。我使用新语法。我设置的 popupController 设置如下
NotificationCenter.default.post(name: .saveFoodGroup, object: self)
dismiss(animated: true, completion: nil)
我创建了一个NotificationCenterExtension.swift
包含名称的文件:
extension Notification.Name {
static let saveFoodGroup = Notification.Name(rawValue: "saveFoodGroup")
}
在我的控制器中,我将观察者设置.viewDidLoad()
为如下:
NotificationCenter.default.addObserver(
forName: .saveFoodGroup,
object: nil,
queue: OperationQueue.main ) {
(notification) in
let groupPopUp = notification.object as! ScalePopUpController
print(groupPopUp)
self.foodGroup = groupPopUp.textInput as? String
}
但是在运行时我不断收到此错误:
unrecognised selector sent to instance 0x7fb9c7e23ef0'
经过一番搜索,我发现当 #selectors 设置不正确时,这是一个旧的 ObjC 错误。但由于我使用的是新语法,这应该不是问题。最后一条线索:当我将鼠标悬停.saveFoodGroup
在NotificatioCenter.default.post(name: .saveFoodGroup
) 调用中的参数上时;我得到了这个神秘的提示;expression produced error: error:
/var/folders/xj/f18tylg51kl33z6c6p2vh34r0000gn/T/expr15-a14342..swift:1:65: 错误:使用未声明的类型“名称”
谁能告诉我这是怎么回事?
完整的错误信息:
2018-12-04 20:17:28.780056+0100 unFatMobile[47399:4108185] -[unFatMobile.ScalePopUpController onBtPRew:]: unrecognized selector sent to instance 0x7fb9c7e23ef0
2018-12-04 20:17:28.787522+0100 unFatMobile[47399:4108185] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[unFatMobile.ScalePopUpController onBtPRew:]: unrecognized selector sent to instance 0x7fb9c7e23ef0'
(
0 CoreFoundation 0x000000010c6b91bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010a6d3735 objc_exception_throw + 48
2 CoreFoundation 0x000000010c6d7f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKitCore 0x000000010f091b4a -[UIResponder doesNotRecognizeSelector:] + 287
4 CoreFoundation 0x000000010c6bded6 ___forwarding___ + 1446
5 CoreFoundation 0x000000010c6bfda8 _CF_forwarding_prep_0 + 120
6 UIKitCore 0x000000010f064ecb -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKitCore 0x000000010eaa00bd -[UIControl sendAction:to:forEvent:] + 67
8 UIKitCore 0x000000010eaa03da -[UIControl _sendActionsForEvents:withEvent:] + 450
9 UIKitCore 0x000000010ea9f31e -[UIControl touchesEnded:withEvent:] + 583
10 UIKitCore 0x000000010f0a00a4 -[UIWindow _sendTouchesForEvent:] + 2729
11 UIKitCore 0x000000010f0a17a0 -[UIWindow sendEvent:] + 4080
12 UIKitCore 0x000000010f07f394 -[UIApplication sendEvent:] + 352
13 UIKit 0x0000000127f0b183 -[UIApplicationAccessibility sendEvent:] + 85
14 UIKitCore 0x000000010f1545a9 __dispatchPreprocessedEventFromEventQueue + 3054
15 UIKitCore 0x000000010f1571cb __handleEventQueueInternal + 5948
16 CoreFoundation 0x000000010c61e721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x000000010c61df93 __CFRunLoopDoSources0 + 243
18 CoreFoundation 0x000000010c61863f __CFRunLoopRun + 1263
19 CoreFoundation 0x000000010c617e11 CFRunLoopRunSpecific + 625
20 GraphicsServices 0x00000001147d41dd GSEventRunModal + 62
21 UIKitCore 0x000000010f06381d UIApplicationMain + 140
22 unFatMobile 0x0000000109d56f47 main + 71
23 libdyld.dylib 0x000000010db52575 start + 1
)
您发布通知的位置(可能是按钮操作)
-[unFatMobile.ScalePopUpController onBtPrew:]
有一个名为onBtPRew
您将其链接到 Ib的操作方法,然后将其删除,这里的通知实现(选择器 && @objc )与此崩溃无关,并且新的内联回调正在工作
Note :
当您在 IB 中复制元素时也会发生这种情况,附加的动作也随它们一起复制,因此请确保断开不相关的动作
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句