我在viewDidLoad()中添加了webservice调用,但是它总是在调用所有其他函数之后恢复执行。下面是我的密码。
override func viewDidLoad() {
super.viewDidLoad()
self.addSlideMenuButton()
getData()
calendarManager = JTCalendarManager.init()
calendarManager.delegate = self
createMinAndMaxDate()
calendarManager.menuView = calendarMenuView
calendarManager.contentView = calendarContentView
}
func getData(){
var request = URLRequest(url: URL(string: "http:xxx")!)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data,
response, error in
guard let data = data, error == nil else {
print("error=\(String(describing: error))")
return
}
else {
do{
//empty eventDetail dictionary
self.Detail = [String: String]() as NSDictionary
let json = try JSONSerialization.jsonObject(with:
data, options:.allowFragments) as! [String:AnyObject]
if let dictionary = json as? [String: Any] {
if let nestedDictionary =
dictionary["xxx_webservices"] as? [String: Any]
{
// access nested dictionary values by key
let dateArray = nestedDictionary["3"] as!
[String:Any]
for details in (dateArray["xxx"] as!
[[String:Any]] ){
// access all key / value pairs in
dictionary
print(details["xxx"]!)
DispatchQueue.main.async (execute: {
() -> Void in
//event details contains details
of an event
self.eventDetail =
nestedDictionary["3"] as!
NSDictionary
})
}
}
}
}
}
catch {
print("Error with Json: \(error)")
}
}
}
task.resume()task.resume()总是在调用日历方法的委托后执行。如何在调用其他委托之前继续执行任务,以便在日历视图中显示数据?谢谢
发布于 2017-08-03 14:28:35
将这些代码添加到web服务中就可以了。
DispatchQueue.main.async {
self.calendarManager.reload()
} 这将使用web服务数据调用日历委托。
https://stackoverflow.com/questions/45461729
复制相似问题