Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 函数不工作后执行函数swift 3_Ios_Swift_Swift3_Ios10 - Fatal编程技术网

Ios 函数不工作后执行函数swift 3

Ios 函数不工作后执行函数swift 3,ios,swift,swift3,ios10,Ios,Swift,Swift3,Ios10,这是我希望在下载所有详细信息后执行的函数,另一个函数是在下载后更新UIElements。此函数位于“CurrentWeather.swift”中 这是在Override func viewDidLoad()上调用它们 现在,当我执行此操作时,它不会更新UI数据 但它是在控制台内打印的 有人能帮我解决这个问题吗在您的请求完成之前,您正在呼叫completed() completed() //<- you need to call the completion handler

这是我希望在下载所有详细信息后执行的函数,另一个函数是在下载后更新UIElements。此函数位于“CurrentWeather.swift”中

这是在Override func viewDidLoad()上调用它们

现在,当我执行此操作时,它不会更新UI数据 但它是在控制台内打印的


有人能帮我解决这个问题吗

在您的请求完成之前,您正在呼叫
completed()

        completed() //<- you need to call the completion handler inside the closure.
    }
    //completed() //<- this would be called before completion
}

completed()//正在异步下载您的weatherDetails。在viewDidLoad()内部,在接收和解析响应之前调用self.updateMainUI()。因此,只需将UIUpdateManui()方法放在该块的内部和末尾:

if let dict  = result.value as? Dictionary<String, AnyObject>{
}
如果让dict=result.value为?字典{
}
如果您是从不同的类请求,那么在那里设计一个协议。在要更新的viewController中对其进行整合。在解析结束时,从上面的if-let块调用要更新的viewController的委托方法。当然,在委托方法中,更新您的UI。 谢谢

 override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self

    currentWeather.downloadWeatherDetails { () -> () in 
        self.updateMainUI()
    }
}
        completed() //<- you need to call the completion handler inside the closure.
    }
    //completed() //<- this would be called before completion
}
if let dict  = result.value as? Dictionary<String, AnyObject>{
}