如何在视图控制器之间传递时显示 activity 指示器
How to show activity indicator while passing between view controller
假设我有 2 个 ViewControllers
,在我的 MainViewController 中我有一个按钮,它执行到 SecondViewController 的 segue。当点击按钮时,我正在将一些初始数据保存到 coreData,因此需要一些时间。
这是我想做的事情;
在 ViewController 之间传递时,我想显示 ActivityIndicator
,但它在 SecondViewController 打开后开始。你可以帮帮我吗?我是 Swift.
的新手
这是我在 MainVC 中使用的代码:
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()
}
}
无需在 prepare(for:sender:)
方法中添加 ActivityIndicator
代码,您需要在 Button 操作中调用它,然后调用 performSegue(withIdentifier:sender:)
方法。
@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)
}
假设我有 2 个 ViewControllers
,在我的 MainViewController 中我有一个按钮,它执行到 SecondViewController 的 segue。当点击按钮时,我正在将一些初始数据保存到 coreData,因此需要一些时间。
这是我想做的事情;
在 ViewController 之间传递时,我想显示 ActivityIndicator
,但它在 SecondViewController 打开后开始。你可以帮帮我吗?我是 Swift.
这是我在 MainVC 中使用的代码:
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()
}
}
无需在 prepare(for:sender:)
方法中添加 ActivityIndicator
代码,您需要在 Button 操作中调用它,然后调用 performSegue(withIdentifier:sender:)
方法。
@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)
}