objective-c - 在加载 tableview 之前检测 iPhone 方向

标签 objective-c uitableview uiinterfaceorientation

所以,我有点纠结……根据 this post ,iPhone/iPad 的方向是纵向的,直到 Controller 内部的“自动旋转”功能告诉 iOS 方向已经改变。我的问题是,在我有机会检测到方向的变化之前,似乎表格 View 单元格正在加载。我的 tableview 取决于设备的方向,所以在知道方向之前我不能加载它。有什么我不知道的吗?

多谢你们!

最佳答案

我相信您正在为应用程序提供对 LAndScape 和 Potrait 模式的支持,因此您应该在 cellForRowAtIndexPath 方法中检测设备方向并为当前方向创建单元格:

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

 Identifier= @"aCell_portrait"

 }else Identifier= @"DocumentOptionIdentifier_Landscape";

关于objective-c - 在加载 tableview 之前检测 iPhone 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7369381/

相关文章:

ios - 如何在没有要 resignFirstResponder 的文本字段时关闭键盘

iphone - 旋转 View 时不触发 UIInterfaceOrientationIsLandscape

iphone - 如何使 icon.png 显示在旧 iphone 上,而 icon@2x.png 显示在较新的 iPhone 上?

swift - 按下单元格时,自定义表格单元格上的 UIButton 会清除背景

iphone - 在 iOS 中存储图像的最佳方式

ios - 静态表格 View 中的单元格内容未显示

ios - 适当的 AutoresizingMask

iOS UIInterfaceOrientation

objective-c - XCode语法着色损坏

iphone - 如何知道从按钮 ios 输入数据时文本字段值是否发生变化