ios - Activity Indicator not appearing -
i have heavy code runs around 0.2 seconds.
i set activity indicator this; however, doesn't show up, rather whole screen freezes around 0.2seconds until code finishes.
func heavywork() { self.actvityindicator.startanimating() ... // heavy loop codes here ... self.activityindicator.stopanimating() } is correct way of using activity indicator?
when comment out
// self.activityindicator.stopanimating() the activity indicator shows , stays there - codes set right.
but ui doesn't seem updated @ right time.
as said, screen freezes without showing activity indicator until heavy code done.
maybe want carry on such pattern instead:
func heavywork() { self.actvityindicator.startanimating() dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), { () -> void in // ... // heavy loop codes here // ... dispatch_async(dispatch_get_main_queue(), { () -> void in self.activityindicator.stopanimating() }) }); } as heavy work should happen in background thread , need update ui on main thread after.
note: assumed call the func heavywork() on main thread; if not, might need distract initial ui updates main thread well.
Comments
Post a Comment