当视图控制器在iPad上显示为弹出窗口时显示导航栏(而不是在显示时按下iPhone)

时间:2014-04-18 17:38:12

标签: ipad uinavigationcontroller segue uipopovercontroller

我正在将iPhone应用程序转换为iPad应用程序。我希望通过将故事板中的segue类型从push更改为popover,将几个视图控制器呈现为以前在iPhone上推送的弹出窗口。视图控制器在导航栏中有标题,完成按钮和取消按钮。现在,当我运行iPad App时,弹出窗口出现但没有导航栏。如何才能显示导航栏。我已经尝试过预期设置它没有隐藏在viewWillAppear中,但它无效。

我已经能够使用以下代码将segue更改为IBAction并使其正常工作。似乎不知何故popover没有导航控制器所以我创建了一个。 `

    // Device is iPad
        addNoteVC = [self.storyboard instantiateViewControllerWithIdentifier:@"addNoteVC"];
        popoverNav = [[UINavigationController alloc] initWithRootViewController:addNoteVC];
        [addNoteVC setManagedObjectContext:self.managedObjectContext];
        [popoverNav.navigationBar setTintColor:[UIColor darkTextColor]];
        NSDictionary *textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [UIColor darkTextColor],NSForegroundColorAttributeName,nil];
        [popoverNav.navigationBar setTitleTextAttributes:textAttributes];
        [addNoteVC setSelectedClient:selectedClient];
        [addNoteVC setAddNoteTableViewControllerDelegate:self];
        popover = [[UIPopoverController alloc] initWithContentViewController: popoverNav];
        [popover setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
        popover.delegate = self;
        [popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
`

虽然上述代码有效,但它与iPhone应用程序代码存在显着差异。我宁愿iPhone和iPad保持尽可能相同。如果为弹出窗口添加另一个导航控制器是唯一的解决方案,我宁愿在自定义segue中执行此操作,因此视图控制器代码可以保持不变。此外,该方法将具有一个自定义segue的经济性,而不是作为弹出窗口呈现的每个视图控制器的变化。如果这确实是最佳解决方案,那么定制segue的细节将受到赞赏和接受。

0 个答案:

没有答案