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 的导出/操作,并确保您没有如下所示的操作:
这将导致您描述的错误消息。如果您有任何与上述无关的操作,只需单击小“x”将其删除。
--
如果您曾经尝试将一个 Action 从 slider 连接到您的 View Controller ,调用该 Action numberOfSounds,但随后在看到 IBAction 时意识到错误,就会发生这种情况代码并继续删除/编辑代码中的 IBAction 函数,但也忽略了调整 IB 中的连接。这是一个常见的工作流程,会导致这种行为。
关于ios - 另一个 "unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33191383/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que