First of all I would try simply accessing the property:
[viewController view];
This will force the lazy load of the view (and thus the subviews and outlets etc.) and this might be enough for you. View controllers by default will not load their view until you access it so this might be why you are seeing a delay.
Forcing a load like this is usually the solution when you are trying to access an outlet property but it hasn't actually been bound yet, like someSubview
in your case.
You can also improve things a bit by adding the view but making it hidden:
viewController.view.hidden = YES;
[mainView addSubview:viewController.view];
Then instead of calling addSubview
when you want to show it, just do:
viewController.view.hidden = NO;
I've used this method when animating in views using the UIViewAnimationTransitionFlipFromRight
etc. transitions. Even when forcing a lazy load of the view there is still a noticable lag, so I've used this to improve the performance a bit.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…