ios - SwiftyJSON showing progressHUD at completion -
i having difficulty displaying progresshud when parsing json using swiftyjson app seems crash if not wait few seconds after showing progresshud.
it not crash if wait few seconds after progress bar disappears means must doing wrong dispatch async queue. unsure of completion handler swiftyjson after parsing api.
the cause of crash array index out of range data not loaded yet.
override func viewdidload() { super.viewdidload() mbprogresshud.showhudaddedto(self.view, animated: true) dispatch_async(dispatch_get_main_queue()) { self.parseapi() mbprogresshud.hidehudforview(self.view, animated: true) self.mytable.reloaddata() } } func parseapi() { let url = nsurl(string: "https://www.kimonolabs.com/api/e0uyfycg?apikey=7v9fhvawkgaspmtvwotnviwzmwipyj0f") let datafromnetwork = nsdata(contentsofurl: url!) let json = json(data: datafromnetwork!) }
you should parse api in background thread, otherwise parse on main thread , block ui until it's finished.
i've had @ mbprogresshud page , seems work this:
override func viewdidload() { super.viewdidload() mbprogresshud.showhudaddedto(self.view, animated: true) dispatch_async(dispatch_get_global_queue( dispatch_queue_priority_low, 0)) { self.parseapi() dispatch_async(dispatch_get_main_queue()) { mbprogresshud.hidehudforview(self.view, animated: true) self.mytable.reloaddata() } } }
Comments
Post a Comment