缺少“主”按钮和滑动手势不工作主/细节ios

时间:2013-11-25 09:24:17

标签: ios objective-c ipad uigesturerecognizer master-detail

我创建了Master详细信息应用程序,其中多个详细视图控制器通过替换segue连接到拆分视图。在横向方向上一切正常,但在纵向方向上我缺少打开主表格视图的按钮,并且在屏幕左侧滑动不起作用而且没有打开应用程序的主侧面。

编辑:

在我的DetailViewController中,我有两个方法,与xcode为master-detail app提供的模板相同:

#pragma mark - Split view

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
    barButtonItem.title = NSLocalizedString(@"MasterButton", @"Master");
    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
    self.masterPopoverController = popoverController;
}

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    // Called when the view is shown again in the split view, invalidating the button and    popover controller.
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    self.masterPopoverController = nil;
}

编辑2: 在更改detailViewController时,我也改变了委托。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UIViewController *destinationViewController = [segue destinationViewController];
    if ([destinationViewController conformsToProtocol:@protocol(UISplitViewControllerDelegate)]) {
        self.splitViewController.delegate = (id)destinationViewController;
    }
    else {
        self.splitViewController.delegate = nil;
    }
}

编辑3: 我最终通过在我创建的每个DetailViewController中添加这行代码来解决我的问题:

self.splitViewController.delegate = self;

2 个答案:

答案 0 :(得分:1)

1)这是针对条形按钮:

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{

    self.popoverController = popoverController;

    barButtonItem.title = NSLocalizedString(@"List", @"List");

   [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];

    self.masterPopoverController = popoverController;
}

2)如果您想添加UIButton,请尝试以下操作:

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{

    self.popoverController = popoverController;

    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateNormal];
        //[btn setImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateHighlighted];
    [btn setFrame:CGRectMake(0, 0, 50, 30)];
    [btn addTarget:barButtonItem.target action:barButtonItem.action forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:btn];
    self.masterPopoverController = popoverController;

}

答案 1 :(得分:0)

您需要从

放置barButtonItem

- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc

详细视图控制器的navigationBar。