Detect iPhone orientation before loading tableview

好久不见. 提交于 2019-12-12 17:44:33

问题


So, I'm in a bit of a bind... According to this post, the orientation of the iPhone/iPad is portrait up to a point after which the "auto-rotate" function inside the controller tells iOS that the orientation has changed. My problem is that it appears as though the tableview cells are loading before I have a chance to detect a change in the orientation. My tableview depends on the orientation of the device, so I can't load it until the orientation is known. Is there something I don't know?

Thanks guys!


回答1:


I believe you are providing support for both the LAndScape and Potrait mode for the application so you should detect the device orientation in the cellForRowAtIndexPath method and create the cell for the current orientation:

if ([UIDevice currentDevice].orientation!=UIDeviceOrientationLandscapeLeft && [UIDevice currentDevice].orientation!=UIDeviceOrientationLandscapeRight) {

 Identifier= @"aCell_portrait"

 }else Identifier= @"DocumentOptionIdentifier_Landscape";



回答2:


When the auto-rotate function is called, you could just run

[tableView reloadData]; 

to reload the table after rotation has occurred.



来源:https://stackoverflow.com/questions/7369381/detect-iphone-orientation-before-loading-tableview

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