开发者

viewWillAppear / viewDidAppear firing multiple times

I am using TabBarKit, and I want to execute a request to pull a new peice of content from a webservice each time a user goes back to a tab.

I can't put the request code in viewDidLoad as its not fired when coming back to the tab. With that said, I've noticed viewWillAppear / viewDidAppear are called multiple times when returning back to a tabs view controller.

I开发者_如何学Pythonf I put the requesting code in there, it is fired multiple times resulting in the webservice being pinged needlessly.

How can I solve this problem? Which method should I place my HTTP request call in so it executes once per view?


You could try setting/checking a downloadInProgress flag before submitting the asynchronous download, then resetting that flag when the request completes.

If you're using something like the ASIHTTPRequest, that calls a delegate method when the request completes or fails, which is the point where you could reset the flag. It allows you to tag each request individually so you can track the success or failure of each one, so this wouldn't restrict you from running one background request at a time.


Turn's out there was an extra call to viewWillAppear in the controller code. If you're interested in following the changes, there is a thread on the issues section of the Git project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜