如何在纵向模式下以详细视图控制器显示导航窗格栏按钮项?

时间:2014-12-02 16:17:22

标签: ios objective-c uisplitviewcontroller

最初,我在Storyboards中手动设置了一个UISplitViewController。我使用导航控制器嵌入了主视图控制器和详细视图控制器。

我唯一的问题是导航窗格栏按钮项目以纵向模式显示,以便用户可以召唤左窗格的桌面视图。

我使用Apple的多视图详细信息代码,完成了此链接中的人员所做的事情:UISplitView with Multiple Detail Views (with Storyboard)

在Storyboard中,我明确设置了主视图和详细视图控制器。我还能够使用NSObject使用Interface Builder设置splitViewController的委托。但是委托(下面)永远不会得到下面的方法:

// "DetailViewManager.h"

-(void)setDetailViewController:(UIViewController<SubstitutableDetailViewController> *)detailViewController
{
    self.detailViewController.navigationPaneBarButtonItem = nil;

    self.detailViewController = detailViewController;

    self.detailViewController.navigationPaneBarButtonItem = self.navigationPaneButtonItem;

    UIViewController *navigationViewController = [self.splitViewController.viewControllers objectAtIndex:0];
    NSArray *viewControllers = [NSArray arrayWithObjects:navigationViewController, self.detailViewController, nil];
    self.splitViewController.viewControllers = viewControllers;

    if (self.navigationPopoverController) {
        [self.navigationPopoverController dismissPopoverAnimated:YES];
    }
}

初始详细信息视图控制器永远不会获取其方法来设置名为的导航栏按钮项:

// "DetailViewController.h"

-(void)setNavigationPaneBarButtonItem:(UIBarButtonItem *)navigationPaneBarButtonItem
{
    if (navigationPaneBarButtonItem != self.navigationPaneBarButtonItem) {
        if (navigationPaneBarButtonItem) {
            [self.navigationController.toolbar setItems:[NSArray arrayWithObject:navigationPaneBarButtonItem] animated:NO];
        } else {
            [self.navigationController.toolbar setItems:nil];
        }
    }
}

每当我第一次将splitViewController设置为rootViewController时尝试以编程方式设置详细视图控制器时,我会使用上面提到的第一个委托方法进入无限循环:

// "LogVC.h"

- (IBAction)loginButtonPressed:(id)sender {

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UISplitViewController *splitViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"splitViewController"];
    DetailViewManager *detailViewManager = (DetailViewManager *)splitViewController.delegate;
    detailViewManager.detailViewController = splitViewController.viewControllers.lastObject;

    UIViewAnimationOptions transitionAnimation;
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
        transitionAnimation = UIViewAnimationOptionTransitionFlipFromLeft;
    } else {
        transitionAnimation = UIViewAnimationOptionTransitionFlipFromTop;
    }

    [UIView transitionWithView:appDelegate.window duration:0.75 options:transitionAnimation animations:^{

        appDelegate.window.rootViewController = splitViewController;

    } completion:nil];

}

我想在Apple提供的代码中无法解决的问题是,当调用委托方法时,因为我不记得他们配置了详细视图控制器,而我在故事板中设置了我的,然后编程。

更新:

我已经能够将Storyboard中的实例化视图控制器作为详细视图控制器传递给我的详细视图管理器,其代码如下:

// "LogVC.h"

UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];

DetailViewManager *detailViewManager = (DetailViewManager *)splitViewController.delegate;
detailViewManager.detailViewController = detailViewController;

详细视图设置正确,并显示。但我仍然缺少左上角的导航窗格栏按钮项。事实上,我错过了顶部的整个导航栏,这是正常的吗?

这是我在详细视图控制器中用于设置导航窗格栏按钮项的代码:

// "DetailViewController.h"

-(void)setNavigationPaneBarButtonItem:(UIBarButtonItem *)navigationPaneBarButtonItem
{
    if (navigationPaneBarButtonItem != _navigationPaneBarButtonItem) {
        if (navigationPaneBarButtonItem) {
            [self.navigationController.toolbar setItems:[NSArray arrayWithObject:navigationPaneBarButtonItem] animated:NO];
        } else {
            [self.navigationController.toolbar setItems:nil];
        }

        _navigationPaneBarButtonItem = navigationPaneBarButtonItem;
    }
}

我觉得我不能简单地将navigationPaneBarButtonItem添加到self.navigationController.toolbar这样,我必须创建自己的工具栏。这是对的吗?

0 个答案:

没有答案