Ios 装载迅速的n定时器

Ios 装载迅速的n定时器,ios,swift,nstimer,Ios,Swift,Nstimer,我正在使用快速加载: 要隐藏它,我使用NSTimer: var timer = NSTimer.scheduledTimerWithInterval(4.0, target: self, selector: #selector(ViewController.update), userInfo: nil, repeats: false) func update() { SwiftLoading().hideLoading() } 函数更新在4秒后启动,函数hideLoading也会启动

我正在使用快速加载:

要隐藏它,我使用NSTimer:

var timer = NSTimer.scheduledTimerWithInterval(4.0, target: self, selector: #selector(ViewController.update), userInfo: nil, repeats: false)

func update()
{
    SwiftLoading().hideLoading()
}
函数更新在4秒后启动,函数hideLoading也会启动,但加载视图保持在屏幕上

有人知道为什么会这样吗

SwiftLoading().hideLoading()
此行创建一个新的快速加载,然后隐藏该快速加载,而不是现有的快速加载

首次创建SwiftLoading时,应将其分配给实例变量,以便稍后隐藏:

let loading = SwiftLoading()    //in your class, as an instance variable
要启动加载对象,请执行以下操作:

loading.showLoading()
loading.hideLoading()
要隐藏加载对象,请执行以下操作:

loading.showLoading()
loading.hideLoading()
此行创建一个新的快速加载,然后隐藏该快速加载,而不是现有的快速加载

首次创建SwiftLoading时,应将其分配给实例变量,以便稍后隐藏:

let loading = SwiftLoading()    //in your class, as an instance variable
要启动加载对象,请执行以下操作:

loading.showLoading()
loading.hideLoading()
要隐藏加载对象,请执行以下操作:

loading.showLoading()
loading.hideLoading()

您确定已启动更新吗?。您是否设置了断点或检查了日志?是否确实触发了更新?。您是否放置了断点或检查了日志?因为它是从计时器触发的,所以可能需要dispatch\u async,因为它不在主线程上@ryantxr NSTimer使用运行循环,因此将在主线程上调用它。“你可能在考虑以后再发邮件。@NobodyNada:哇,这解决了我的问题!不,它发射正确,非常感谢!由于它是从计时器触发的,因此可能需要dispatch\u async,因为它不在主线程上@ryantxr NSTimer使用运行循环,因此将在主线程上调用它。“你可能在考虑以后再发邮件。@NobodyNada:哇,这解决了我的问题!不,它发射正确,非常感谢!