Slow UIViewController load time (slow ClientState warning)

£可爱£侵袭症+ 提交于 2019-12-21 12:33:39

问题


Since I converted an old app to iOS 6 I've started getting the following message in my console.

WARNING: Slow defaults access for key ClientState took 0.023656 seconds, tolerance is 0.020000

Other than updating my code from iOS 5 to iOS 6, I also switched over to auto-layout. I've run Instruments/Time Profiler and the rootViewController in my appDelegate is the problem. Everytime I switch view controllers it sucks the vast major of the time, (regardless of whether I have to instantiate the view controller or re-using one which already exists).

window.rootViewController = myViewController;

I know what the method does superficially, but I'm not sure what happens under the covers... what would cause it to be slow now and what can I do to speed it up?

EDIT: I've tried taking my storyboard off auto-layout and the problem vanishes (of course my UI layout is in shambles). So the obvious conclusion is, it's something about auto-layout. I've probably just under 70 views all combined on the screen and the various constraints needed to lay them out. I have a hard time believing auto-layout is that much slower (from ~80ms with auto-layout turned off to ~1370ms with auto- layout turned on).


回答1:


Having 70 views on-screen sounds like a lot! My proposal is to make it simpler in some way:

  • Do you REALLY need all 70 views at the same time?

  • Check if all views need autolayout, remove it where-ever possible

  • Can some views be replaced by graphics? I've used views e.g. for shadows, might have been images

Can you split storyBoard into several smaller ones e.g. one for login, details, edit mode etc. Part of the slowness might come from system having to deal with (too) big storyBoards.




回答2:


Consider creating a new project with 2 view controllers and test the switching speed. Every iOS app has a window, a root view controller and a view controller. The problem isn't likely to be as narrow and clear-cut as you may be hoping. What does each view controller load? Did you inspect the underlying code? Does app delegate do anything on initialization or change of root view controller?



来源:https://stackoverflow.com/questions/14300381/slow-uiviewcontroller-load-time-slow-clientstate-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!