Ios 线程1:EXC_BAD_指令(代码=EXC_i386_INVOP,子代码=0x0),当计时器调用函数时

Ios 线程1:EXC_BAD_指令(代码=EXC_i386_INVOP,子代码=0x0),当计时器调用函数时,ios,swift,Ios,Swift,我遇到了两个问题,第一个问题是每次计时器调用此函数时,我都会收到上面描述的错误消息(其中包括一个漂亮的崩溃): func updateTime(){ 注意:(#imageLiteral(resourceName:“play.png”)显示为一个小的白色矩形。如果我尝试类似于playbauseOutlet.setImage(UIImage(名为:“play.png”),例如:.normal)它也会崩溃 我用这段代码假装要做的是根据显示状态将按钮的“播放”图像更改为“暂停”图像,反之亦然。请提前感谢

我遇到了两个问题,第一个问题是每次计时器调用此函数时,我都会收到上面描述的错误消息(其中包括一个漂亮的崩溃):

func updateTime(){

注意:
(#imageLiteral(resourceName:“play.png”)
显示为一个小的白色矩形。如果我尝试类似于
playbauseOutlet.setImage(UIImage(名为:“play.png”),例如:.normal)
它也会崩溃


我用这段代码假装要做的是根据显示状态将按钮的“播放”图像更改为“暂停”图像,反之亦然。请提前感谢!

这种崩溃通常发生在您的界面生成器中没有连接时。根据您的评论,尝试
播放PauseOutlet.setImage(UIImage(名为:“play.png”)),for:。normal)
它崩溃了我会仔细检查这个UIButton的IB连接你知道吗?我确信我连接了所有东西,但我再次检查,发现tempo label和playpauseOutlet根本没有连接。非常感谢!很高兴提供帮助。这种情况经常发生
    let currentTime = Int(player.currentTime)

    let minutes = currentTime/60
    let seconds = currentTime - minutes * 60

    if seconds < 10 {

        tempo.text = String(minutes) + ":0" + String(seconds)

    } else {

        tempo.text = String(minutes) + ":" + String(seconds)

    }

    durationSliderOutlet.value = Float(player.currentTime)

    if currentTime == Int(player.duration - 1) {

        playpauseOutlet.setTitle("Play", for: .normal)
        isPlaying = false

    }

    print("currentTime: \(currentTime)")
    print(Int(player.duration))
    print("minutes: \(minutes)")
    print("seconds: \(seconds)")
    print(isPlaying)

}
if seconds < 10 {

    tempo.text = String(minutes) + ":0" + String(seconds)

} else {

    tempo.text = String(minutes) + ":" + String(seconds)

}
 @IBAction func playpauseButton(_ sender: UIButton) {

    if isPlaying == false {

        playpauseOutlet.setImage(#imageLiteral(resourceName: "pause.png"), for: .normal)
        player.play()
        isPlaying = true


    } else {

        playpauseOutlet.setImage(#imageLiteral(resourceName: "play.png"), for: .normal)
        player.pause()
        isPlaying = false


    }
}