我的应用程序遇到了一些问题。当我按下UIButton
时,消息线程1:信号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。有人能帮我弄清楚这意味着什么吗?
答案 0 :(得分:1)
那是因为timer == 1
并不意味着什么。函数更新将由计时器调用,您可以自己保留计数器并递增它。
答案 1 :(得分: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
}