gpt4 book ai didi

ios - 试图返回开始 : unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 14:50:17 28 4
gpt4 key购买 nike

在结果页面之后,我希望用户按下“完成”并返回到列表中的第一个问题。目前,应用程序崩溃并显示“无法识别的选择器已发送到实例。

2018-04-19 11:56:49.072392-0400 test[62142:269319] -[test.ResultsController done]: unrecognized selector sent to instance 0x7f8c62f43b10
2018-04-19 11:56:49.078012-0400 test[62142:269319] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[test.ResultsController done]: unrecognized selector sent to instance 0x7f8c62f43b10'
*** First throw call stack:
(
0 CoreFoundation 0x0000000114a8b1e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000011074d031 objc_exception_throw + 48
2 CoreFoundation 0x0000000114b0c784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000011192c9eb -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x0000000114a0d898 ___forwarding___ + 1432
5 CoreFoundation 0x0000000114a0d278 _CF_forwarding_prep_0 + 120
6 UIKit 0x00000001116ff6f8 -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKit 0x0000000112104271 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 154
8 UIKit 0x00000001121041aa -[_UIButtonBarTargetAction _invoke:forEvent:] + 154
9 UIKit 0x00000001116ff6f8 -[UIApplication sendAction:to:from:forEvent:] + 83
10 UIKit 0x000000011187aab4 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x000000011187add1 -[UIControl _sendActionsForEvents:withEvent:] + 450
12 UIKit 0x0000000111879d19 -[UIControl touchesEnded:withEvent:] + 580
13 UIKit 0x00000001117743cf -[UIWindow _sendTouchesForEvent:] + 2729
14 UIKit 0x0000000111775ad1 -[UIWindow sendEvent:] + 4086
15 UIKit 0x0000000111719620 -[UIApplication sendEvent:] + 352
16 UIKit 0x000000012ed78e6b -[UIApplicationAccessibility sendEvent:] + 85
17 UIKit 0x000000011205a717 __dispatchPreprocessedEventFromEventQueue + 2796
18 UIKit 0x000000011205d32c __handleEventQueueInternal + 5949
19 CoreFoundation 0x0000000114a2dbb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x0000000114a124af __CFRunLoopDoSources0 + 271
21 CoreFoundation 0x0000000114a11a6f __CFRunLoopRun + 1263
22 CoreFoundation 0x0000000114a1130b CFRunLoopRunSpecific + 635
23 GraphicsServices 0x00000001184aea73 GSEventRunModal + 62
24 UIKit 0x00000001116fe367 UIApplicationMain + 159
25 test 0x000000010fe329e0 main + 48
26 libdyld.dylib 0x0000000115c6c955 start + 1
27 ??? 0x0000000000000001 0x0 + 1

) libc++abi.dylib:以 NSException 类型的未捕获异常终止(lldb)

我读过问题可能是它在代码中的位置,但它似乎没问题?

下面是按钮的创建:

        override func viewDidLoad() {
super.viewDidLoad()

navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Done", style: .plain, target: self, action: Selector(("done")))

navigationItem.title = "Results"

view.backgroundColor = UIColor.white

view.addSubview(resultsLabel)
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": resultsLabel]))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": resultsLabel]))

let names = ["Ross", "Joey", "Chandler", "Monica", "Rachel", "Phoebe"]

var score = 0
for question in QuestionController.questionsList {
score += question.selectedAnswerIndex!
}

let result = names[score % names.count]
resultsLabel.text = "Congratulations! \(result)."
}

func done() {
navigationController?.popToRootViewController(animated: true)

最佳答案

需要注意的几点:

  • 您在 done 函数中错过了发送者的参数
  • 使用#selector,它是类型安全的并且会抛出编译错误
  • Objective-C 方法需要加上前缀@objc

按钮:

navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Done",
style: .plain,
target: self,
action: #selector(done(sender:)))

功能:

@objc func done(sender: UIBarButtonItem) {

navigationController?.popToRootViewController(animated: true)

}

关于ios - 试图返回开始 : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49925493/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com