gpt4 book ai didi

ios - master 中的快速分割 View 导航

转载 作者:行者123 更新时间:2023-11-29 00:42:17 25 4
gpt4 key购买 nike

我创建了一个新的分割 View ,并在界面生成器中向主视图添加了另外 2 个表格 View ,并更新了 segues,如下所示:

storyboard

一切都按预期工作,除了在 iphone plus 上,当我以纵向模式导航到第二个 TableView Controller 并转到横向时,分屏显示在主控中我的第一个表和详细信息中第二个表。

splitscreen

如果我在第一个表上横向显示,则在主表中我有第一个表,详细信息中是应有的详细信息,如果我在主表中导航,则导航会在主表中发生,因为它应该

如何让它始终在分割 View 的详细信息中显示详细信息 View Controller ?

最佳答案

我想通了,答案是swift 3.0

// This is called every time the splitview is shown, and it decides what to show in the detail
// Since we need the details to always show the detail, we should always return the detail
// but if we return the detail when we already are on detail it will make the splitview show
// the detail in both views; so we try to detect when we are on detail
func splitViewController(_ splitViewController: UISplitViewController, separateSecondaryFrom primaryViewController:UIViewController) -> UIViewController? {
var is_detail = false

// because we have to nav controllers linked to the split view, the primary will always be nav
if let nav = primaryViewController as? UINavigationController {
// if the top controller of primary is yet another nav controller, this means we navigated to the detail (follow the arrow, and count the nav controllers :D)
if let nav2 = nav.topViewController as? UINavigationController {
// now just to be thourough, we check to see if there is a DetailViewController
if nav2.topViewController is DetailViewController {
is_detail = true
}
}
}

// if the primary is actually a detail, we return nil, and let splitview to do it's job
if is_detail {
// splitview will show in the master the previous view controller & in detail the current view controller
return nil
} else {
// splitview will keep the current view controller in master, and add this controller in detail
let storyboard = UIStoryboard(name: "Main", bundle: nil)
return storyboard.instantiateViewController(withIdentifier: "DetailView")
}
}

关于ios - master 中的快速分割 View 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39151763/

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