为什么我的导航控制器工具栏第一次在分割视图中显示时与我的表格视图重叠?

发布于 2024-11-02 08:14:03 字数 2738 浏览 0 评论 0原文

我正在开发一个 iPad 应用程序,它使用 UISplitViewController 作为窗口的 rootViewController 。分割视图的详细信息视图控制器是一个包含 UITableViewControllerUINavigationViewController。分割视图控制器和导航视图控制器都是以编程方式创建的,并且不使用笔尖。表视图控制器是一个自定义类,它使用普通表视图委托方法扩展了 UITableViewController

当应用程序以纵向模式运行时,我可以单击按钮来显示弹出窗口,并且我的导航视图和表格视图在弹出窗口中显示良好:

Popover in Portrait

但是,第一次旋转到横向并且拆分视图在左侧显示导航视图和表格视图时,导航视图的工具栏与表格视图的第一行重叠:

横向分割视图,表视图被遮挡

您可以看到表视图被遮挡,并且看不到包含“大象”的行。奇怪的是,如果我将设备旋转回纵向,然后再次返回横向,表格视图不再被遮挡:

横向拆分视图,表格视图完全可见

我需要做什么才能在设备第一次旋转到横向时表格视图正确显示?

编辑:

UISplitViewControllerapplication:didFinishLaunchingWithOptions: 中创建,其 viewControllers 属性设置为包含我的数组UINavigationController(分割视图用语中的主控制器)位于索引 0 处,UIWebView 的控制器位于索引 1 处。

UINavigationController通过 [[UINavigationController alloc] initWithRootViewController:tableViewController] 创建。 tableViewController 实例是 UITableViewController 的子类。具体来说,这里是接口声明:

@interface LocalRevisionsList :
  UITableViewController <NSFetchedResultsControllerDelegate> {}

tableViewController 的初始化如下:

tableViewController =
  [[LocalRevisionList alloc] initWithNibName:@"LocalRevisionList" bundle:nil];

如果有帮助,我可以提供 .xib 中的信息。但是,即使我在没有 xib 的情况下初始化表视图(tableViewController = [[LocalRevisionList alloc] init]),我仍然第一次看到显示问题。 LocalRevisionList 中唯一被重写的操作是 viewDidLoad。这是完整的(只是为了表明我们在这里没有做任何古怪的事情):

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"My Title";    
    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error])
    {
        abort();
    }
}

编辑 2:

我没有使用分割视图模板项目创建这个项目,但我一直在引用它试图找出我正在做的事情和该项目所做的事情之间的区别。我发现的唯一区别是模板项目在 .xib 内设置分割视图及其子视图控制器,而我以编程方式创建大部分控制器。

当我打破 shouldAutorotateToInterfaceOrientation: 并转储根视图控制器的框架时,我看到:

(gdb) print (CGRect)[[self view] frame]
$2 = {
  origin = {
    x = 0, 
    y = 0
  }, 
  size = {
    width = 768, 
    height = 1004
  }
}

打印导航控制器的框架,这是我的分割视图数组中的第一个控制器,我看到这个:

(gdb) print (CGRect)[[[self localArticlesNavController] view] frame]
$3 = {
  origin = {
    x = -320, 
    y = 0
  }, 
  size = {
    width = 320, 
    height = 1004
  }
}

负 x 值很有趣,但我不认为这给我带来了问题。即使当我旋转回纵向,然后再次返回横向时,这些帧值与第一次时相同(当视图显示不正确时)。

I'm working on an iPad application that uses a UISplitViewController as the rootViewController for my window. The detail view controller for the split view is a UINavigationViewController that contains a UITableViewController. Both the split view controller and navigation view controller are created programmatically and do not use a nib. The table view controller is a custom class that extends UITableViewController with the normal table view delegate methods.

When the app is running in portrait mode, I can click my button to display my popover and my navigation view and table view show up fine in the popover:

Popover in portrait

However, the first time that I rotate to landscape and the split view shows the navigation view and table view on the left, the navigation view's toolbar overlaps the first row of the table view:

Split view in landscape with table view obscured

You can see that the table view is obscured and the row containing "elephant" cannot be seen. The strange thing is that if I rotate the device back to portrait, then back to landscape again, the table view is no longer obscured:

Split view in landscape with table view fully visible

What do I need to do so that the table view displays correctly the first time the device is rotated to landscape?

Edit:

The UISplitViewController is created in application:didFinishLaunchingWithOptions: and its viewControllers property is set to an array containing my UINavigationController (the master controller in split view parlance) at index 0, and the UIWebView's controller at index 1.

The UINavigationController is created via [[UINavigationController alloc] initWithRootViewController:tableViewController]. The tableViewController instance is a subclass of UITableViewController. Specifically, here is the interface declaration:

@interface LocalRevisionsList :
  UITableViewController <NSFetchedResultsControllerDelegate> {}

The tableViewController is initialized thus:

tableViewController =
  [[LocalRevisionList alloc] initWithNibName:@"LocalRevisionList" bundle:nil];

If it's helpful, I can provide information from the .xib. However, even when I initialize the table view without the xib (tableViewController = [[LocalRevisionList alloc] init]), I still see the display problem the first time. The only overridden operations in LocalRevisionList is viewDidLoad. Here it is in full (just to show we're not doing anything wacky here):

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"My Title";    
    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error])
    {
        abort();
    }
}

Edit 2:

I did not create this project using the Split View template project, but I've been referring to that trying to find the difference between what I'm doing and what that project does. The only difference I've found is that the template project sets up the split view and its child view controllers inside the .xib, whereas I create most of my controllers programatically.

When I break inside shouldAutorotateToInterfaceOrientation: and dump the root view controller's frame, I see:

(gdb) print (CGRect)[[self view] frame]
$2 = {
  origin = {
    x = 0, 
    y = 0
  }, 
  size = {
    width = 768, 
    height = 1004
  }
}

Printing the frame of my navigation controller which is the first controller in my split view array, I see this:

(gdb) print (CGRect)[[[self localArticlesNavController] view] frame]
$3 = {
  origin = {
    x = -320, 
    y = 0
  }, 
  size = {
    width = 320, 
    height = 1004
  }
}

The negative x value is interesting, but I don't think it's causing me the problem here. Even when I rotate back to portrait, then back to landscape again, these frame values are the same as they were the first time (when the view displays incorrectly).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文