What is correct place for threading either in viewWillAppear or viewDidAppear in UIViewController .
-
what kind of task you are going to do. can you give some idea??? – Vineet Singh Apr 09 '13 at 09:13
-
Check out this answer - http://stackoverflow.com/a/5659007/1586880. – dsgriffin Apr 09 '13 at 09:14
-
do you ask about background thread to run webservice? – Mani Apr 09 '13 at 09:14
-
Like loading image from server using GrandCentralDispatch . – Undertaker Apr 09 '13 at 09:15
-
Please explain briefly,... When will you load image from server ? Either once or often loaded whenever you get apper into screen?(navigation push, pop, dismissmodal.... ).... mention whenever you want to load image from server? – Mani Apr 09 '13 at 09:19
-
In push navigation either at viewWillAppear or viewDidAppear ?So what is the correct place for load image . – Undertaker Apr 09 '13 at 09:21
1 Answers
in general, if you want to load images that need to be seen (appear) with all other views of your view controller, then you need to load in a SYNC way (you need to wait until image is loaded before your viewController is shown) in viewWillAppear:
this way you can animate your view controller (including your image), but, of course, you may keep in mind that loading images from servers need time (and internet errors may occur), so, it may happens that a user tap to go to your viewControllers and then your app stops for a while (maybe too much, depending on the file size of your image, internet speed connection...)
So, a better approach could be:
load images in viewDidAppear in ASYNC way:
user see animation immediately to your viewController (without image) and will see your image when it will be available (with a new animation, if you will).
anyway, it depends on what you aspect your app should do, both ways could be good...

- 6,175
- 1
- 23
- 36