gpt4 book ai didi

swift - 当我尝试使用 NSTimer 更改 View Controller 时出错(EXC_BAD_INSTRUCTION)

转载 作者:行者123 更新时间:2023-11-30 12:58:05 25 4
gpt4 key购买 nike

我试图在动画之后更改 View Controller 。动画完成后,我使用 NSTimer 来更改 View Controller 。动画发生在给定的默认 ViewController 上。该动画运行一次后,应该使用 prepareForSegue 函数并转到第二个 View Controller 。当我运行它时,动画可以工作,但它不会更改 View Controller 。

What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?

import UIKit

class ViewController: UIViewController, UIViewControllerTransitioningDelegate {
@IBOutlet weak var imageView: UIImageView!

var timer = NSTimer()

override func viewDidLoad() {
super.viewDidLoad()

var imagesNames = ["stairs", "stairs2", "stairs3", "stairs4", "stairs5", "stairs6", "stairs7", "stairs8", "stairs9", "stairs10", "stairs11", "stairs12", "stairs13", "stairs14", "stairs15", "stairs16", "stairs17", "stairs18", "stairs19", "stairs20", "stairs21", "stairs22", "stairs23", "stairs24", "stairs25", "stairs26", "stairs27", "stairs28", "stairs29", "stairs30", "stairs31", "stairs32", "stairs33", "stairs34", "stairs35", "stairs36", "stairs37", "stairs38", "stairs39", "stairs40", "stairs41", "stairs42", "stairs43", "stairs44", "stairs45", "stairs46","stairs47", "stairs48", "stairs49", "stairs50", "stairs51","stairs52", "stairs53", "stairs54", "stairs55", "stairs56","stairs57"]

var images = [UIImage]()

for i in 0..<imagesNames.count{
images.append(UIImage(named: imagesNames[i])!)
}

imageView.animationImages = images;
imageView.animationDuration = 4;
imageView.startAnimating()

_ = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: false)
}

func timeToMoveOn() {
self.performSegueWithIdentifier("goToMainUI", sender: self)
}

最佳答案

屏幕截图中的控制台输出中有一条线索。

您正在隐式展开imageView,但它是nil。这可能意味着没有 ImageView 连接到该 socket 。

关于swift - 当我尝试使用 NSTimer 更改 View Controller 时出错(EXC_BAD_INSTRUCTION),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40186936/

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