2016-11-08 62 views
0

可以说我有2 ViewControllers,在我的MainViewController我有一个按钮,执行segue到SecondViewController。当点击按钮时,我将一些初始数据保存到coreData,因此需要一些时间。如何显示活动指标,而在视图控制器之间传递

这是我想要做的事情; 在ViewControllers之间传递时,我想显示ActivityIndicator,但它在SecondViewController打开后启动。你可以帮帮我吗?我是Swift新手。

这是我在MainVC使用的代码:你需要调用它的按钮行动,并呼吁performSegue(withIdentifier:sender:)方法之后

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

     if (segue.identifier == "SecondViewController") { 

      SwiftSpinner.show("Loading") // Act. indicator found on github 

      willRunOnce() // Here Im saving data to CoreData 

      SwiftSpinner.hide() 
     } 

    } 
+0

您必须出示按钮点击微调后必须隐藏它'prepareForSegue' – Aditya

回答

1

而是在prepare(for:sender:)方法加入ActivityIndicator代码。

@IBAction func onBtnSkip(_ sender: UIButton) { 

    SwiftSpinner.show("Loading") // Act. indicator found on github 
    willRunOnce() // Here Im saving data to CoreData 
    SwiftSpinner.hide() 

    //Now performSegue 
    self.performSegue(withIdentifier: "identifier", sender: nil) 
} 
+0

它并没有为我工作 –

+0

会告诉你什么是'willRunOnce()',它是做任何异步调用? –

+0

没有进行异步调用,是否与此相关?,可能是:) –

相关问题