开发者

iPhone : how to bring up the UI faster?

I'm currently developing a client similar to twitter. The app has 5 tabs, and are all table views controllers.

It seems simple enough, but the start up time (from hitting the app on the menu..to the black screen+status bar ...to the user interface) is 18 seconds!

I want to slice this down to at least 5-6 seconds and don't want to have a splash开发者_运维知识库 screen. Can someone please give me some pointers on how to bring up the UI faster? E.g. Certain methods I should be using / correct spots where I should be making API calls?

(P.S. right now almost 90% of my initial API calls are being made in the (id)init{} method)


Running through the debugger adds a lot of time to the start up. Have you timed it running off a regular start? It sounds like this 15-20 seconds is your time while running through the debugger, since the bootstrapper kills off apps that take too long to start up.

Aside from that, it sounds like you're doing API calls during the start up as well. Are these synchronous or asynchronous API calls? You'll probably want to be doing asynchronous API calls, since blocking the main UI thread is a big no-no. If they are synchronous calls, an easy way to get around them is to pack them in a single method and then use [NSThread detachNewThreadSelector:toTarget:withObject:].

Once all your data is loaded, just update the UI with the new data (but make sure to do it in the main thread, since touching UI elements outside the main thread is another big no-no. Using [NSObject performSelectorOnMainThread:withObject:waitUntilDone] is one way to do it.


You should first add some NSLog timestamps to see where exactly you're losing all this time. Then it will be more clear what can be optimized.


One of my apps has five tabs as well (but only three table view controllers), and it starts up in aobut 6 seconds (as you're trying to achieve). I've noticed that only the contents of the first tab are loaded on startup. The remaining ones are loaded when you touche the tab for the first time.

So the clue could be to make sure your tabs are initialized lazily, and I'm guessing this is not yet the case with your app. My app has 6 XIB files, one for the main window and 5 for the contents of each tab. Is your UI organized the same way?

Assuming your UI is not loaded lazily, you could set breakpoints in the viewDidLoad: methods of your tab contents and see who is loading them so early.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜