gpt4 book ai didi

swift - 计时器功能崩溃的应用程序

转载 作者:行者123 更新时间:2023-12-03 17:49:00 24 4
gpt4 key购买 nike

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!
var timer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(ViewController.runTimedCode), userInfo: nil, repeats: true)

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.
}

@objc func runTimedCode() {

imageView.image = UIImage(named: "card10")
}

}

此代码给我消息“无法识别的选择器发送到实例”,但我不知道问题出在哪里。有人可以帮帮我吗? :)

最佳答案

尝试以下方法:

class ViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!
var timer: Timer? = nil

override func viewDidLoad() {
super.viewDidLoad()

timer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(ViewController.runTimedCode), userInfo: nil, repeats: true)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@objc func runTimedCode() {

imageView.image = UIImage(named: "card10")
}
}

关于swift - 计时器功能崩溃的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48842356/

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