gpt4 book ai didi

ios - 无法识别的选择器...错误?

转载 作者:行者123 更新时间:2023-11-28 13:00:36 25 4
gpt4 key购买 nike

我根据其他人指出的内容编辑了一些代码,但我不断收到上述错误,说我发送了一个“无法识别的选择器”。我的计时器的选择器,最初是错误的,已被修改,但 Xcode 仍在提示。

这是我的代码:

import UIKit

class ViewController: UIViewController {

@IBOutlet var instructionsNew: UILabel!

@IBOutlet var lockStatusNew: UIImageView!

@IBOutlet var timerText: UILabel!



@IBAction func hackLockButton(sender: AnyObject){

var counter = 0





let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "updateCounter", userInfo: nil, repeats: true)
func updateCounter() {
timerText.text = String(counter++)
}

while(timerText.text == "1") {instructionsNew.text = "loading"}

while(timerText.text == "2"){instructionsNew.text = "loading."}

while(timerText.text == "3") {instructionsNew.text = "loading.."}

while(timerText.text == "4"){instructionsNew.text = "loading..."}

while(timerText.text == "5") {instructionsNew.text = "hack successful!"
lockStatusNew.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.
}


}

请帮我找出问题所在。谢谢!

最佳答案

问题是,您在 hackLockButton 函数中添加了 updateCounter。您应该将该方法放在该函数之外,它会起作用。

@IBAction func hackLockButton(sender: AnyObject)
{
// Code here
}

func updateCounter()
{
timerText.text = String(counter++)
}

建议:

您不想编写 while(timerText.text == "1") {instructionsNew.text = "loading"} 来显示该标签。它可能会导致无限循环并挂起您的 UI。而是使用像这样的开关盒:

switch(counter)
{
case 1: instructionsNew.text = "loading"
// Write other cases too
}

关于ios - 无法识别的选择器...错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33997907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com