views:

56

answers:

3

I have a multiple view based application, the problem is that when I push one UIViewController the device (only when I test it on a real device) freezes for a second or two, I don't know why is this happening since the pushed UIViewController has only one UITextField & a button. This only happens when the view is pushed the first time, after this pushing the view is smooth.

Any ideas on how to avoid this?

+1  A: 

Are there any objects you can instantiate that are separate from the view controller you're pushing, which you can instantiate earlier? "Pre-loading" objects will help give the appearance of a faster view controller push.

Alex Reynolds
Only fancy things I have in that UIViewController is a UITextField with a Red Courier Font. When the view is pushed I make the keyboard pop-up automatcally, when I dont make it pop up automatically the transition is great. It is not until I tap the UITextField to edit it that the application freezes for a second and then the keyboard appears. Is it because the font used is not already instantiated? What should I do?
El Developer
You can instantiate fonts in your app delegate. Keep a property in your app delegate that you access from your view controllers. You can manage a "style sheet" of sorts by instantiating `UIFont` and `UIColor` instances in the app delegate or a separate "style" singleton class, making properties easily available to all other classes in your app.
Alex Reynolds
Thanks, I will try that!
El Developer
A: 

Seems like you have something heavy on leaving the original view controller.

Can you post the exact code (the entire method around the push) of pushing the controller?

Michael Kessler
+1  A: 

You should definitely use Instruments to find out what's happening at the time when you first push that controller.

Use the Intrument's CPU sampler tool and start a recording. Then do whatever you need to do in your app to push the controller. You will probably see a spike in the CPU-load chart. You can investigate stack traces at this point to find out what's happening and why that takes so long.

Nikolai Ruhe