X $ C $Ç

编程入门 行业动态 更新时间:2024-10-08 20:35:38
本文介绍了X $ C $Ç - 型NSException的未捕获的异常终止当按钮被pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新的应用程序开发,我跟随苹果的教程了解。我已经经历了很多询问这种类型的错误问题显得但他们都不是我的帮助。在本教程中,我卡上的添加按钮,将显示部分,在那里我试图实现一个字符串当按钮被窃听的控制台上打印出/点击。只有这样,当我得到一个错误。

I'm new to app development and I'm following Apple's tutorial to learn. I've looked through a lot of questions asked about this type of error but none of them are helping me. In the tutorial, I'm stuck on the "Add Buttons to the View" section where I'm trying to implement a string to be printed out on the console when a button is tapped/clicked on. Only I get an error when doing so.

我的code在斯威夫特按钮:

import UIKit class StarRatingControl: UIView { // MARK: Initialization required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) let button = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44)) button.backgroundColor = UIColor.cyanColor() button.addTarget(self, action: "ratingButtonTapped", forControlEvents: .TouchDown) addSubview(button) } override func intrinsicContentSize() -> CGSize { return CGSize(width: 240, height: 44) } // MARK: Button Action func ratingButtonTapped(button: UIButton) { print("Button pressed!") } }

错误:

2015-09-16 12:43:17.409 FoodTracker[954:13341] -[FoodTracker.StarRatingControl ratingButtonTapped]: unrecognized selector sent to instance 0x7f939b7a43b0 2015-09-16 12:43:17.443 FoodTracker[954:13341] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FoodTracker.StarRatingControl ratingButtonTapped]: unrecognized selector sent to instance 0x7f939b7a43b0' *** First throw call stack: ( 0 CoreFoundation 0x00000001079f59b5 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001095f4deb objc_exception_throw + 48 2 CoreFoundation 0x00000001079fdfdd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010794b9fa ___forwarding___ + 970 4 CoreFoundation 0x000000010794b5a8 _CF_forwarding_prep_0 + 120 5 UIKit 0x0000000108214522 -[UIApplication sendAction:to:from:forEvent:] + 92 6 UIKit 0x0000000108373c06 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x0000000108373eac -[UIControl _sendActionsForEvents:withEvent:] + 273 8 UIKit 0x0000000108372b1c -[UIControl touchesBegan:withEvent:] + 261 9 UIKit 0x000000010827bf50 -[UIWindow _sendTouchesForEvent:] + 308 10 UIKit 0x000000010827cd4d -[UIWindow sendEvent:] + 865 11 UIKit 0x00000001082312ae -[UIApplication sendEvent:] + 263 12 UIKit 0x000000010820d36c _UIApplicationHandleEventQueue + 6693 13 CoreFoundation 0x0000000107921b21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 14 CoreFoundation 0x0000000107917a4c __CFRunLoopDoSources0 + 556 15 CoreFoundation 0x0000000107916f03 __CFRunLoopRun + 867 16 CoreFoundation 0x0000000107916918 CFRunLoopRunSpecific + 488 17 GraphicsServices 0x000000010befead2 GSEventRunModal + 161 18 UIKit 0x000000010821299e UIApplicationMain + 171 19 FoodTracker 0x00000001078118dd main + 109 20 libdyld.dylib 0x000000010a11392d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

我的理解是X code保持行动/老引用我已经删除了,所以我尝试在视图控制器在Interface Builder中右键单击找到的感叹号旁边的项目,但我couldn网点找不到任何东西(仅在故障排除方法,我知道至今)。我用X code测试版7.0。任何帮助AP preciated!

I understand that Xcode keeps old references to action/outlets that I've deleted so I tried right-clicking on the View Controller in the Interface Builder to find items with the exclamation point next to them but I couldn't find anything(only troubleshooting method I know of so far). I'm using Xcode beta 7.0. Any help is appreciated!

推荐答案

您错过了:在选择,请尝试以下操作来代替:

You're missing the ":" in the selector, try the following instead:

button.addTarget(self, action: "ratingButtonTapped:", forControlEvents: .TouchDown)

我希望这帮助你。

I hope this help you.

更多推荐

X $ C $Ç

本文发布于:2023-11-26 19:16:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634853.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!