2016-08-04 28 views
0

Das ist mein Code. Ich möchte einen Indikator anzeigen, wenn ich beim Übergeben von Daten und Hinzufügen von Daten zur Datenbank auf die Schaltfläche klicke. Wie kann ich es reparieren?Ladeanzeige funktioniert nicht richtig

@IBAction func addWishList(sender: AnyObject) { 
    self.loading.startAnimating() 
     addMovie(showMovie!) // Database add method. 
} 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {() -> Void in 
     let controller : WishListViewController = segue.destinationViewController as! WishListViewController 

     if segue.identifier == "segue" { 
      controller.user = self.tmpUser // data from Facebook to pass another controller 
      dispatch_async(dispatch_get_main_queue(), {() -> Void in 
       self.loading.stopAnimating() 
      }) 
     } 
    }) 
} 

Antwort

0

Ihre addMovie Hauptwarteschlange blockiert. Sie müssen etwas Verzögerung geben, um es zur nächsten Ausführungsschleife hinzuzufügen. Versuchen Sie mit:

@IBAction func addWishList(sender: AnyObject) { 
    self.loading.startAnimating() 
    //This will add to next main run loop. 
    let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.0 * Double(NSEC_PER_SEC))) 
    dispatch_after(dispatchTime, dispatch_get_main_queue(), { 
      addMovie(showMovie!) // Database add method. 

    }) 
} 
0

tun wie folgt ..

@IBAction func addWishList(sender: AnyObject) { 

     self.loading.startAnimating() 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {() -> Void in 

      addMovie(showMovie!) // Database add method. 

    dispatch_async(dispatch_get_main_queue(), {() -> Void in 
    self.loading.stopAnimating() 

    }) 
    }) 

}