Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 另一个";已将无法识别的选择器发送到实例";_Ios_Swift - Fatal编程技术网

Ios 另一个";已将无法识别的选择器发送到实例";

Ios 另一个";已将无法识别的选择器发送到实例";,ios,swift,Ios,Swift,编辑3: 对于其他人来说,这就是这里发生的错误 我最初将滑块的iAction创建为“numberOfSounds”。 然后,我创建了一个名为“numberOfSounds”的类属性,并将其重命名 将IBAction更改为“sliderValueChanged” 我希望连接自动更新连接,但是 事实并非如此。所以,由于我对变量使用了相同的名称,我 没有接通。请参见下面的@rob接受答案,了解相关信息 线索 解决方案是删除以前的连接,并控制从情节提要中的滑块拖动到ViewController中的sli

编辑3:

对于其他人来说,这就是这里发生的错误

我最初将滑块的iAction创建为“numberOfSounds”。 然后,我创建了一个名为“numberOfSounds”的类属性,并将其重命名 将IBAction更改为“sliderValueChanged”

我希望连接自动更新连接,但是 事实并非如此。所以,由于我对变量使用了相同的名称,我 没有接通。请参见下面的@rob接受答案,了解相关信息 线索

解决方案是删除以前的连接,并控制从情节提要中的滑块拖动到ViewController中的sliderValueChanged iAction

原始问题:

我遇到了这个非常常见的错误,和其他许多人一样,我很难理解修复方法。操纵滑块会导致崩溃,这是以下消息:

2015-10-17 13:35:59.765测试应用程序[25969:2985698]***终止应用程序 由于未捕获的异常“NSInvalidArgumentException”,原因: '-[Test_App.ViewController numberOfSounds:]:无法识别的选择器 已发送到实例0x7fc439e26740'

断点位于“numberOfSounds=Int(sender.value)”上

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

我已经通读了谷歌搜索“发送到实例的未识别选择器”的前15-20个搜索结果,但仍然没有找到解决问题的方法

谢谢你的帮助

编辑:(添加更多代码)

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

2015-10-17 13:59:24.303测试应用[26230:3006546] -[Test_App.ViewController numberOfSounds:]:发送到实例0x7fedea730350的未识别选择器2015-10-17 13:59:24.313测试 应用程序[26230:3006546]*由于未捕获异常而终止应用程序 “NSInvalidArgumentException”,原因:“-[Test_App.ViewController” numberOfSounds::发送到实例的选择器无法识别 0x7fedea730350' *第一次抛出调用堆栈:(0 CoreFoundation 0x000000010a7d7f65异常预处理+165 1 libobjc.A.dylib
0x000000010c469deb objc_异常_抛出+48 2 CoreFoundation
0x000000010a7e058d-[NSObject(NSObject)未识别选择器:]+ 205 3核心基金会0x000000010a72df7a ___转发\uu
+970 4 CoreFoundation 0x000000010a72db28\u CF\u转发\u准备\u 0+120 5 UIKit
0x000000010aff41fa-[UIApplication sendAction:to:from:forEvent:][92 6 UIKit 0x000000010b158504 -[UIControl发送操作:到:forEvent:+67 7 UIKit 0x000000010b1587d0-[UIControl\u发送操作预防:带事件:+311 8 UIKit 0x000000010b244770-[UISlider BegindKingWithTouch:withEvent:+1083 9 UIKit
0x000000010b15739d-[UIControl触摸开始:withEvent:+136 10 UIKit 0x000000010b05e894-[UIWindow _sendTouchesForEvent:+308 11 UIKit 0x000000010b05f691-[UIWindow sendEvent:+865 12 UIKit
0x000000010b011752-[UIApplication sendEvent:+263 13 UIKit
0x000000010afecfcc\u UIApplicationHandleEventQueue+6693 14 CoreFoundation 0x000000010A704A1 CFRUNLOOP\u正在调用\u OUT\u以执行\u SOURCE0\u函数+17 15 CoreFoundation 0x000000010a6f9fcc __CFRunLoopDoSources0+556 16核心基金会0x000000010a6f9483\ucfrunlooprun+867 17核心基金会
0x000000010a6f8e98 CFRunLoopRunSpecific+488 18图形服务
0x000000010ed6cad2 GSEventRunModal+161 19 UIKit
0x000000010aff2676 UIApplicationMain+171 20测试应用程序
0x000000010a5fc1ad main+109 21 libdyld.dylib
0x000000010cfb092d启动+1 22???
0x0000000000000001(0x0+1)


指示灯问题是
-[Test\u App.ViewController numberOfSounds:
中存在冒号。这意味着您有一些东西正试图用一个参数调用名为
numberOfSounds:
的方法

假设您的代码中没有这样做的内容,我会在“Connections Inspector”IB中仔细检查滑块的出口/操作,并确保您没有如下操作:

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

--


如果您曾经尝试将一个动作从滑块连接到视图控制器,调用动作
numberOfSounds
,但在看到
iAction
代码时意识到错误,并继续删除/编辑代码中的
iAction
函数,但忽略了调整IB中的连接,则可能会发生这种情况,也这是导致这种行为的常见工作流

你确定是代码导致了这个问题,而这正是你的Xcode中的代码,只是复制了它(不是重新键入它?),因为在操场上复制它并调用函数时没有任何错误problem@luk2302应该这样。它是更不相关代码的子集。嗯,让我快速测试一下。例如,just works:/正如它应该的那样,还没有任何可能出错的地方^^清除任何断点并在出现异常时检查堆栈回溯。该代码如图所示works@Paulw11这不是错误消息所说的。故事板中的控件连接到名为“numberOfSounds:”的操作,该操作未在“ViewController”中实现。这是一个动作,不是一个属性获取者。好的,我有你的剪辑显示的确切内容。我想知道这里发生了什么。我原
import UIKit
import AVFoundation

class ViewController: UIViewController {
  var numberOfSounds: Int = 0

  @IBAction func sliderValueChanged(sender: UISlider) {
    numberOfSounds = Int(sender.value)
  }
}
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.
  }
}