ios - Swift 中的复杂导航栈
<p><p>我有一个复杂的导航问题,我希望有人能给我一些关于解决这个问题的最佳方法的见解。我一直在谷歌上搜索,发现了针对类似问题的多种不同建议,但似乎没有一个能完全确定我的问题。</p>
<p>我有一个 UITabBarController。每个选项卡都设置了它自己的导航堆栈,这是应该的。</p>
<p>其中一个选项卡使用具有三个段的 UISegmentedControl。这些段中的每一个都需要有自己的 ViewController 和导航堆栈,彼此独立,并且独立于选项卡栏 Controller 为其选项卡控制的导航堆栈。基本上,它需要像 UITabBarController 的选项卡中的 UITabBarController 一样工作,但将选项卡显示为 UISegmentedControl。</p>
<p>另外,当在每个选项卡的根 Controller 时,导航堆栈应该是它进来的堆栈,以便它弹出到它进来的 TableView 。</p>
<p>我遇到了障碍,觉得无论我尝试什么,我都必须进行一些残酷的破解才能继续前进。任何和所有的帮助将不胜感激。</p>
<p>我非常希望能够在 Storyboard 中处理连接,以使我的 Storyboard 保持美观,但如果必须在代码中完成,我也可以这样做。</p>
<h2>编辑</h2>
<p>我有一个解决办法。在基类中:</p>
<pre><code> private func show(segment: SelectedSegment) {
var equipmentStoryboard: UIStoryboard!
switch segment {
case .SelEquipment:
equipmentStoryboard = UIStoryboard(name: "EquipmentDetailEquipmentSegment", bundle: nil)
case .SelHistory:
equipmentStoryboard = UIStoryboard(name: "EquipmentDetailHistorySegment", bundle: nil)
case .SelPlans:
equipmentStoryboard = UIStoryboard(name: "EquipmentDetailPlansSegment", bundle: nil)
}
if let newSegmentController = equipmentStoryboard.instantiateViewController(withIdentifier: segment.getSegmentIdentifier()) as? EquipmentDetailSegmentsViewController {
var controllerStack = self.navigationController?.viewControllers
controllerStack?.removeLast()
controllerStack?.append(newSegmentController)
self.navigationController?.setViewControllers(controllerStack!, animated: false)
}
}
@IBAction func didTapSegmentedControl(_ sender: UISegmentedControl, forEvent event: UIEvent) {
let newSelectedSegment = SelectedSegment(rawValue: sender.selectedSegmentIndex)
self.show(segment: newSelectedSegment!)
}
</code></pre>
<p>不过,我对此并不满意。我愿意:</p>
<ol>
<li>不必在每次点击段时重新实例化每个 Controller 。</li>
<li>能够为它制作 Storyboard(如果没有实际的 UISegmentedControlController 或类似的东西,可能无法实现)</li>
</ol></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我实际上找到了解决问题的正确方法。我必须编写一个自定义系统。我将在某个时候回到这个问题上并继续努力,以便我可以提供一个带有 API 的 github 项目,该 API 可以公开向任何人提供此功能。</p>
<p>基本上,系统会这样做:</p>
<ul>
<li>可滚动分段控件,可根据需要扩展到任意多个分段。</li>
<li>一个“SegmentNavigationController”,它是一个 UIViewController,因为它包含在点击相应的段时交换到、置于前面、显示和隐藏的 View 。
<ul>
<li>每个段都有自己的导航堆栈,它只是一个 ViewController 数组,用于控制当前段中的 View 。</li>
<li>自定义动画在向/从导航堆栈推送和弹出项目时发生,使其看起来像一个自然的 iOSController 。分段控件保持原位,而新 View 动画化。</li>
<li>保留导航,以便在分段之间切换时,您可以在点击不同分段时从中断处继续。</li>
</ul></li>
<li>利用 Clean Swift 架构:<a href="http://clean-swift.com" rel="noreferrer noopener nofollow">http://clean-swift.com</a> </li>
</ul>
<p>我将其发布为答案,因为经过几天的审议,<strong>自定义系统是最佳解决方案</strong>。</p>
<p>当然,这也是可能将此系统扩展到有用和可重用的东西的初步。</p></p>
<p style="font-size: 20px;">关于ios - Swift 中的复杂导航栈,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/44835176/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/44835176/
</a>
</p>
页:
[1]