作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我写了两个 Swift 函数(只是一个选择题测验应用)
func createQuestions() // this goes to Parse, and fetches the questions data that are going to question the users and store them into local arrays
func newQuestion() // this also fetches some other data (for example, some incorrect choices) from Parse and read local variables and finally set the labels to correctly display to the users
我想在ViewDidLoad
中,先执行createQuestion()
,完全完成后再运行newQuestion()
。否则,newQuestion()
在读取本应获取的局部变量时会出现一些问题。我将如何管理它?
编辑:我学会了使用闭包!另一个跟进问题。我正在使用 for 循环来创建问题。但是,问题是for循环并没有按顺序执行。然后我对重复函数 (vocabTestedIndices) 的检查失败了,它会带来两个相同的问题。我想让for循环一个一个的执行,这样创建的题目就不会重叠了。 code image
最佳答案
尝试
override func viewDidLoad() {
super.viewDidLoad()
self.createQuestions { () -> () in
self.newQuestion()
}
}
func createQuestions(handleComplete:(()->())){
// do something
handleComplete() // call it when finished stuff what you want
}
func newQuestion(){
// do other stuff
}
关于ios - Swift 如何让一个函数在另一个函数完成后执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34985108/
我是一名优秀的程序员,十分优秀!