点击按钮时无法识别的选择器错误
Unrecognized selector error when I tap a button
我的应用程序出现问题。当我按下 UIButton
.
时,消息 Thread 1: Signal SIGABRT 不断弹出
这是我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet var instructions: UILabel!
@IBOutlet var lockStatus: UIImageView!
@IBAction func hackButton(sender: AnyObject) {
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: false)
while(timer == 1){instructions.text = "loading"}
while(timer == 2){instructions.text = "loading."}
while(timer == 3) {instructions.text = "loading.."}
while(timer == 4){instructions.text = "loading..."}
while(timer == 5) {instructions.text = "hack successful!"
lockStatus.image = UIImage(named: "unlocked.png")
timer.invalidate()
}
}
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.
}
}
我检查了调试器,它一直说我向实例 0x7fa7baebc4c0 发送了一个无法识别的选择器。谁能帮我看看这是什么意思?
那是因为 timer == 1
没有任何意义。函数更新将由计时器调用,您可以从那里自己保留一个计数器并递增它。
您在创建计时器时尝试使用一种名为 "update" 的方法,但您的代码(至少您共享的部分)没有更新功能。
@IBAction func hackButton(sender: AnyObject) {
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: false)
}
func update() { // do your updates here
}
我的应用程序出现问题。当我按下 UIButton
.
这是我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet var instructions: UILabel!
@IBOutlet var lockStatus: UIImageView!
@IBAction func hackButton(sender: AnyObject) {
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: false)
while(timer == 1){instructions.text = "loading"}
while(timer == 2){instructions.text = "loading."}
while(timer == 3) {instructions.text = "loading.."}
while(timer == 4){instructions.text = "loading..."}
while(timer == 5) {instructions.text = "hack successful!"
lockStatus.image = UIImage(named: "unlocked.png")
timer.invalidate()
}
}
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.
}
}
我检查了调试器,它一直说我向实例 0x7fa7baebc4c0 发送了一个无法识别的选择器。谁能帮我看看这是什么意思?
那是因为 timer == 1
没有任何意义。函数更新将由计时器调用,您可以从那里自己保留一个计数器并递增它。
您在创建计时器时尝试使用一种名为 "update" 的方法,但您的代码(至少您共享的部分)没有更新功能。
@IBAction func hackButton(sender: AnyObject) {
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: false)
}
func update() { // do your updates here
}