简体   繁体   English

UISplitViewController:在detailView中导航

[英]UISplitViewController: Navigating within detailView

I have an app with a SplitView that lets you add companies to a database. 我有一个带有SplitView的应用程序,可让您将公司添加到数据库中。 In the masterView the companies are shown with their respective company names. 在masterView中,将显示公司及其各自的公司名称。 Tapping on one of these companies shows me the address in a "viewCell" (not actually a cell just a view within a viewController, just easier to explain). 轻触这些公司之一,就会在“ viewCell”中显示地址(实际上,一个单元不是viewController中的一个视图,更容易解释)。 Below that "viewCell" is a tableView (still in the same viewController) with one row: "Employees". 在该“ viewCell”下面是一个tableView(仍在同一viewController中),其中有一行:“ Employees”。 Tapping on that leads me to a new tableViewController that lists all the employees that I can add or that I added. 轻按该按钮,便会导致我进入一个新的tableViewController,其中列出了我可以添加或添加的所有员工。

I would like to use a navBarItem to go back and forth between the CompanyDetailViewController and the EmployeesTableViewController. 我想使用navBarItem在CompanyDetailViewController和EmployeesTableViewController之间来回移动。

On iPhone this works nicely with a transition with the automatically created "< Back" navBarItem. 在iPhone上,通过自动创建的“ <Back” navBarItem进行过渡时,此功能可以很好地工作。 On iPad this does not work. 在iPad上,这不起作用。 It does not show any navBarItem. 它不显示任何navBarItem。 I know the reason (the EmployeeTableViewController "thinks" it's the detailView of the masterView, hence it does not need one), but I'd like to be able to transition back and worth with an animation. 我知道原因( EmployeeTableViewController “认为”它是masterView的detailView,因此它不需要一个),但是我希望能够转换回去并值得使用动画。

My prepareForSegue from the CompanyDetailView to EmployeesTableViewController looks like this: 我从CompanyDetailViewEmployeesTableViewController prepareForSegue看起来像这样:

if (segue.identifier == "ShowEmployeesSegue")
{
    let controller = (segue.destinationViewController as! UINavigationController).topViewController as! EmployeesTableViewController
    controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
    controller.navigationItem.leftItemsSupplementBackButton = true

    controller.coreDataStack = coreDataStack
    controller.companyToView = companyToView as? Company
}

Update: Some Screenshots 更新:一些截图

  • iPhone: http://i.stack.imgur.com/ivl86.png iPhone: http//i.stack.imgur.com/ivl86.png

    1. MasterView with 3 Test Companies MasterView与3家测试公司

    2. DetailView of Test Company 1 测试公司1的详细视图

    3. List of employees of Test Company 1 after tapping on Employees, "< Back"-Button visible 点击“员工”后,测试公司1的员工列表,“ <返回”按钮可见

  • iPad: http://i.stack.imgur.com/ObBto.png iPad: http//i.stack.imgur.com/ObBto.png

    1. MasterView with DetailView of Test Company 1 MasterView与测试公司1的DetailView

    2. List of Employees of Test Company 1, No "< Back"-Button visible to go back to DetailView of Test Company 1 测试公司1的员工列表, 没有“ <返回”按钮可见返回测试公司1的DetailView

Based on some understanding, the following could be your solution. 根据一些理解,以下可能是您的解决方案。

Check in the code, if the action for it is showDetailViewController:sender. 检入代码(如果执行的操作是showDetailViewController:sender)。

Open the select Storyboard -> Open as Source Code. 打开选择的Storyboard->作为源代码打开。 Find your object (might be by x and y). 找到您的对象(可能是x和y)。

The working connection segue should like the below 工作连接顺序应如下所示

<connections>
               <segue destination="UXJ-Si-1aa" kind="show" id="aDD-wp-6dZ"/>

</connections>

Delete the action if you might have and try again, in the following way. 如果可能,请删除该操作,然后按以下方式重试。 Select the button, cntrl + drag the pointer to your ViewController. 选择按钮, cntrl +将指针拖到您的ViewController。 Shown in images 如图所示

If you have segue like the below one would not work , and will not show UINavigationBar 如果您像下面这样进行搜索,将无法正常工作 ,并且不会显示UINavigationBar

    <connections> 
    <segue destination="UXJ-Si-1aa" kind="show" action="showDetailViewController:sender:" id="A8L-Ad-PKT"/> 

</connections>

在此处输入图片说明

在此处输入图片说明

Now I know what caused it. 现在我知道是什么原因造成的。 I embedded the employeeViewController in a NavigationController. 我将employeeViewController嵌入了NavigationController中。 I connected it directly and now it works. 我直接连接了它,现在它可以工作了。 I simply needed to change the prepareForSegue-method like so: 我只需要像下面这样更改prepareForSegue方法:

if (segue.identifier == "ShowEmployeesSegue") {
let controller = segue.destinationViewController as! EmployeesTableViewController
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true

controller.coreDataStack = coreDataStack
controller.companyToView = companyToView as? Company }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UISplitViewController与tableView作为detailView错误 - UISplitViewController with tableView as detailView bug UITableView,uisplitviewcontroller-一种管理detailview的方法? - UITableView, uisplitviewcontroller - a way to manage detailview? 根据UISplitViewController中的masterview更改detailview - Change detailview according to masterview in UISplitViewController UISplitViewController detailview更改结果是灰色区域 - UISplitViewController detailview changing result is gray area 在UISplitViewController中将Int从MasterView传递给DetailView - Passing an int from MasterView to DetailView in a UISplitViewController UISplitViewController中的UITableViewController - UITableViewController within UISplitViewController 在UISplitviewCOntroller中将JSQMessagesViewController用作detailView时,KeyBoardToolBar只需要出现在DetailViewController中 - When using JSQMessagesViewController as detailView in UISplitviewCOntroller, KeyBoardToolBar needs to appear in DetailViewController only UITabBarController中的UISplitViewController中的黑条 - black bar in UISplitViewController within UITabBarController 如何使用UIContainerView在iPad上的UISplitViewController主菜单上隐藏嵌入式辅助UITableViewController的DetailView - How can hide on iPad an embedded secondary UITableViewController's DetailView on a UISplitViewController master using UIContainerView 在标签 Controller 内导航 - Navigating within Tab Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM