2

前提非常简单:我想在使用 UISplitViewController 的 iPad 应用程序中显示模式视图。

视图层次结构很简单:

                                              /- TableViewController1
                     /- root:TabBarController -- TableViewController2
SplitViewController -
                     \- detail:CustomViewController

当我单击 TableViewController1 中的一个表格单元格时,我打开了一个模式视图:

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip {
  UIViewController *vc = [[MyModalClass alloc] init];
  UINavigationController *nc = [[UINavigationController alloc]
                                initWithRootViewController:vc];
  nc.modalPresentationStyle = UIModalPresentationFormSheet;
  nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  [self presentModalViewController:nc animated:true];
  [nc release];
  [vc release];
}

这工作得很好:视图出现了。当我尝试以横向以外的任何方向将其关闭时,问题就开始了。

在 ModalViewController 中,导航栏中的 UITabBarButton 会触发以下方法:

- (void) closeButtonInNavBarWasClicked:(id)sender {
  [self dismissModalViewControllerAnimated:true];
}

这就是问题开始的地方。

调用此代码时,模态视图消失了,但是:TabBarController(拆分视图的根视图)突然旋转并调整了大小。内容突然侧身,部分覆盖了细节视图。详细信息视图的大小没有调整为更小,它只是被根视图部分覆盖。

唯一没有出现此问题的情况是当我在应用程序处于纵向模式时点击 TableViewController1 单元格时。尽管根视图位于弹出窗口中(这可能是大量错误的来源),但一切正常。

我已经尝试过一些事情,但没有成功:

  • 转储标签栏,只显示 TableViewController1 作为拆分视图的根控制器
  • 创建一个委托协议,以便父 TableViewController1 关闭模式视图而不是 MyModalClass 视图本身。
  • 在 TableViewController1.splitViewController 上呈现/关闭模态视图实际上使事情变得更糟:视图甚至没有出现。
  • 牺牲几只山羊也无济于事。

我将非常感谢有关此问题的任何意见。

4

2 回答 2

0

我对自己的问题有一个答案:我使用 Instruments 系统地消除了我的应用程序中的所有内存泄漏。一旦我这样做了,问题就消失了。

于 2010-10-24T21:10:12.630 回答
0

我和你有同样的问题,我通过编程暂时强制旋转我的呈现视图控制器(一旦返回它),在它的 viewDidAppear 方法中进行任意旋转来解决它。当然没有动画。然后将其旋转回所需的方向(我在旋转之前保存)。

因此,如果 vc1 模态显示 vc2,并且用户旋转 vc2,我通过调用根据 vc2 的当前方向设置 vc1 的方向: UIInterfaceOrientation currentOrientation = self.interfaceOrientation; //存储vc2的当前方向(模态视图)[vc1 willRotateToInterfaceOrientation:currentOrientation duration:0];

然后我解雇 vc2 并在 vc1 的 viewWillAppear 中执行以下操作:

-(无效)viewDidAppear:(BOOL)动画{

[super viewDidAppear:animated];

/* Store wanted orientation */
UIInterfaceOrientation currentOrientation = self.interfaceOrientation; 

/* rotate to some arbitrary orientation, this solves the bug. */
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO]; 

[[UIDevice currentDevice] setOrientation:currentOrientation animated:NO]; //restore wanted orientation.

}

于 2013-02-27T10:24:50.910 回答