Ich habe zwei Controller. In der ersten habe ich einen Fortschrittsbalken und es gibt eine Anfrage, dass ich Daten und eine Schleife bekomme. Ich muss einen Balken aktualisieren, der während der Schleife auf dem ersten Controller ist. Das Problem besteht darin, dass ein Schrägstrich nur aktualisiert wird, wenn eine Methodenausführung beendet wird, auch wenn eine Schleife nicht aktualisiert wird.Aktualisierung der Fortschrittsanzeige während der Schleife
Firstview:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
for i in 0 ..< JSON.count {
autoreleasepool{
count = count + 1
if count >= percentage {
progress = progress + 1
//This notification executes the method that makes the update in the first view
NSNotificationCenter.defaultCenter().postNotificationName("ProgressNotification", object: nil, userInfo: ["label":"Clientes", "progress" : progress])
count = 0
}
}
}
}
SecondView:
// Methode, die die Symbolleiste aktualisiert
func addProgress(notification:NSNotification){
dispatch_async(dispatch_get_main_queue()) {
self.progressBar.setProgress(CGFloat.init(notification.userInfo!["progress"] as! Int), animated: true)
self.progressLabel.text = notification.userInfo!["label"] as? String
}
}