gpt4 book ai didi

ios - 另一个 "unrecognized selector sent to instance"

转载 作者:搜寻专家 更新时间:2023-10-31 22:21:50 25 4
gpt4 key购买 nike

Edit 3:

For other people getting this error, this is what happened here.

I originally created the IBAction for the slider as "numberOfSounds". I then created a class property called "numberOfSounds" and renamed the IBAction to "sliderValueChanged".

I expected the connection to automatically update the connection, BUT IT DOESN'T. So, since I dumbly used the same name for the variable, I missed the connection. See @rob accepted answer below for the telltale clue.

The solution was to delete the previous connection and control-drag from the slider in the storyboard to the sliderValueChanged IBAction in the ViewController.

原始问题:

我遇到了这个极其常见的错误,并且像许多其他人一样,我很难理解修复方法。操作 slider 会导致崩溃,即此消息:

2015-10-17 13:35:59.765 Test App[25969:2985698] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test_App.ViewController numberOfSounds:]: unrecognized selector sent to instance 0x7fc439e26740'

断点在“numberOfSounds = Int(sender.value)”。

import UIKit
import AVFoundation

class ViewController: UIViewController {
var numberOfSounds: Int = 0

@IBAction func sliderValueChanged(sender: UISlider) {
numberOfSounds = Int(sender.value)
}
}

我想我理解了一些问题,尽管 numberOfSounds 是 ViewController 的一个属性,但它在 sliderValueChanged 的​​范围内不可用。

我已经阅读了“无法识别的选择器发送到实例”的前 15-20 个谷歌搜索,但仍然没有找到似乎可以解决问题的内容。

感谢您的帮助。

编辑:(添加更多代码)

class ViewController: UIViewController {
var numberOfSounds: Int = 0

@IBAction func sliderValueChanged(sender: UISlider) {
numberOfSounds = Int(sender.value)
}
@IBOutlet weak var numberOfSoundsLabel: UILabel!
@IBAction func PlaySound(sender: UIButton) {}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

编辑 2:(添加完整堆栈跟踪)

2015-10-17 13:59:24.303 Test App[26230:3006546] -[Test_App.ViewController numberOfSounds:]: unrecognized selector sent to instance 0x7fedea730350 2015-10-17 13:59:24.313 Test App[26230:3006546] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test_App.ViewController numberOfSounds:]: unrecognized selector sent to instance 0x7fedea730350' * First throw call stack: ( 0 CoreFoundation 0x000000010a7d7f65 exceptionPreprocess + 165 1 libobjc.A.dylib
0x000000010c469deb objc_exception_throw + 48 2 CoreFoundation
0x000000010a7e058d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010a72df7a ___forwarding_
+ 970 4 CoreFoundation 0x000000010a72db28 _CF_forwarding_prep_0 + 120 5 UIKit
0x000000010aff41fa -[UIApplication sendAction:to:from:forEvent:] + 92 6 UIKit 0x000000010b158504 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x000000010b1587d0 -[UIControl _sendActionsForEvents:withEvent:] + 311 8 UIKit 0x000000010b244770 -[UISlider beginTrackingWithTouch:withEvent:] + 1083 9 UIKit
0x000000010b15739d -[UIControl touchesBegan:withEvent:] + 136 10 UIKit 0x000000010b05e894 -[UIWindow _sendTouchesForEvent:] + 308 11 UIKit 0x000000010b05f691 -[UIWindow sendEvent:] + 865 12 UIKit
0x000000010b011752 -[UIApplication sendEvent:] + 263 13 UIKit
0x000000010afecfcc _UIApplicationHandleEventQueue + 6693 14 CoreFoundation 0x000000010a7040a1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 15 CoreFoundation 0x000000010a6f9fcc __CFRunLoopDoSources0 + 556 16 CoreFoundation 0x000000010a6f9483 __CFRunLoopRun + 867 17 CoreFoundation
0x000000010a6f8e98 CFRunLoopRunSpecific + 488 18 GraphicsServices
0x000000010ed6cad2 GSEventRunModal + 161 19 UIKit
0x000000010aff2676 UIApplicationMain + 171 20 Test App
0x000000010a5fc1ad main + 109 21 libdyld.dylib
0x000000010cfb092d start + 1 22 ???
0x0000000000000001 0x0 + 1 )

最佳答案

明显的问题是 -[Test_App.ViewController numberOfSounds:] 中存在冒号。这意味着您有一些东西正在尝试使用一个参数调用名为 numberOfSounds: 的方法。

假设您的代码中没有任何会执行此操作的内容,我会仔细检查“Connections Inspector”IB 中 slider 的导出/操作,并确保您没有如下所示的操作:

enter image description here

这将导致您描述的错误消息。如果您有任何与上述无关的操作,只需单击小“x”将其删除。

--

如果您曾经尝试将一个 Action 从 slider 连接到您的 View Controller ,调用该 Action numberOfSounds,但随后在看到 IBAction 时意识到错误,就会发生这种情况代码并继续删除/编辑代码中的 IBAction 函数,但也忽略了调整 IB 中的连接。这是一个常见的工作流程,会导致这种行为。

关于ios - 另一个 "unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33191383/

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