1

Assume we have one UIViewController, call it A, in the viewDidLoad of that VC we add to it two UIViewControllers( B,C ). now to make the UI smooth in the viewDidLoad of A we do some GCD work

  dispatch_queue_t queue = dispatch_queue_create("myqueue", NULL);
  dispatch_async(queue, ^{
  // Create webviews, do some setup here, etc etc
  // Perform on main thread/queue
   dispatch_async(dispatch_get_main_queue(), ^{
  // this always has to happen on the main thread
    [self.view addSubview:webView];
   });
 });

So the ParentViewController is somewhat better in UI rendenring.

My question is: Is this enough GCD work? or should I do the same thing in thew viewDidLoad of the child viewcontrollers? just because I created those child VC's on a background thread does that mean I need not do any GCD wokr on them? I am trying to make my UI as responsive as possible, but not clutter the code. I guess another way of wording this would be are GCD threads reentrant? is there a concept of reentrancy in iOS?

yeesterbunny
  • 1,847
  • 2
  • 13
  • 17
Huang
  • 1,355
  • 2
  • 11
  • 28
  • Are you actually having a performance problem that you have investigated, and identified view setups as the cause of? – jrturton Feb 24 '13 at 22:29
  • Well I was able to boost some performance by implementing this code. I justs wanted to know whether the affects of this trickle down the hieraqrcy of viewcontrollers. – Huang Feb 25 '13 at 19:44

1 Answers1

0

I don't think that adding a subview is a significant performance hit. Also, playing with views (or UIKit in general) should be done on the main UI thread. As far as I know it's considered bad practice to do such things in the background.

Try to save GCD/Async stuff to processor-intensive work or tasks of unknown durations such as downloading something from the internet.

Source and more info: Warning: UIKit should not be called from a secondary thread

Community
  • 1
  • 1
Rowan Freeman
  • 15,724
  • 11
  • 69
  • 100
  • well adding a generic view is not, but maybe adding a uiwebview that loads some pdf file, or some complex view is. – Huang Feb 25 '13 at 19:44