gpt4 book ai didi

ios - UISplitViewController 不会在横向模式下隐藏 masterViewController

转载 作者:行者123 更新时间:2023-11-29 13:31:10 26 4
gpt4 key购买 nike

注意: 在阅读这个问题之前请注意,我已经阅读了前面的问题,这些问题解释了苹果实现 UISplitViewController 的不足以及我应该如何使用开源的“MGSplitViewController”,因为简单地在 Split View上隐藏主视图 Controller 并不容易横向模式下的 Controller 。请记住,我仅限于在 iOS 5.1 中使用普通的 UISplitViewController。

现在进入问题:

我有一个 Split View Controller ,左侧是 TableView (主视图),右侧是详细 View Controller 。我正在使用导航 Controller 来控制左侧,这是一个转换到另一个 TableView (“DataTableViewController”)的 TableView 。为了隐藏这个左侧,我在详细 View Controller 的导航工具栏上放置了一个“隐藏”按钮。按下隐藏按钮时,我更改了“_hideMaster”属性:

-(IBAction)hidePressed
{
_hideMaster = !_hideMaster;
// Must manually reset the delegate back to self in order to force call "shouldHideViewController"
self.splitViewController.delegate = nil;
self.spliteViewController.delegate = self;

}

然后在 SplitViewController 委托(delegate)中自动调用此方法:

// This is called when I change the delegate from nil back to self.
- (BOOL)splitViewController: (UISplitViewController*)svc shouldHideViewController: (UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return _hideMaster;
}

当我调试它时,我可以看到一切都按计划进行,并且当它进入方法 splitViewController:shouldHideViewController:inOrientation:

时属性具有正确的值

唯一的问题是什么也没有发生。我最左边的 TableView (DataTableViewController) 没有消失。当我仔细观察时,委托(delegate)方法中的 (UIViewController *)vc 参数不是我要隐藏的 TableView Controller ,而是与此 TableView 关联的导航 Controller 。所以本质上它是在试图隐藏导航 Controller ——这显然不是我想要的……

如何才能使自动调用的委托(delegate)方法 (shouldHideViewController:) 中的 UIViewController 参数调用与该导航 Controller 关联的最顶层 View Controller ? (毕竟我想隐藏DataTableViewController)

最佳答案

我是这样处理的。如果 MasterViewController 在回来的路上没有实例化,可能需要做更多的工作才能重新出现。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
[[self.splitViewController.viewControllers lastObject] view].frame = self.splitViewController.view.frame;
[UIView commitAnimations];

关于ios - UISplitViewController 不会在横向模式下隐藏 masterViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11856312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com