【问题标题】:Tab Bar disappears on segue标签栏在segue上消失
【发布时间】:2019-03-03 07:36:19
【问题描述】:

我想要达到的目标:

  • 我有一个"Login" ViewController,它与Tab Bar Controller 相连。
  • 我的Tab Bar Controller 转到Navigation Controller,然后"Home" ViewController 转到Table View。这个视图是我的“主页/欢迎”页面。我希望底部有一个选项卡栏以及一个可以使用原型单元格编辑的静态表。每个单元格转到不同的ViewController
  • 然后,我希望能够点击每个单元格(我现在有“信息”设置),它会转到相应的ViewController。现在,“信息”单元格应该转到第二个Navigation Controller,然后是"Information" ViewController
  • 从那里,我想要另一个可以用原型单元编辑的静态表。每个单元将转到一个单独的 ViewController 堆栈。

我的问题: 当我从"Home" ViewController 中的“信息”单元格中切换时,信息标签栏“向上推”,标签栏消失。我已经尝试过其他 segue 表单,但它们都没有维护 Tab Bar。 我想要它,以便您可以使用 Tab Bar 导航到 Info ViewController 或使用 Home/Welcome ViewController 上的单元格导航到 Info 页面。

此时我根本没有代码,我只是在使用这些 segues。 有谁知道如何实现我想要实现的目标,如果是这样,请提供尽可能多的示例代码,因为我对 Swift 非常陌生。

任何帮助表示赞赏!谢谢:)

【问题讨论】:

  • 在您共享的屏幕上看不到东西。

标签: ios swift uitableview uitabbarcontroller segue


【解决方案1】:

不要添加segue 来打开"Information" ViewController,它是UITabBarController 的一部分。

您必须使用didSelectRowAttableview 中选择单元格。只需在其中添加一行即可:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true) {
    self.tabBarController?.selectedIndex = 1
}

这将更改选项卡并打开"Information" ViewController

如果您想在"Information" ViewController 中加载与单元格选择相关的数据,您可以使用ProtocolsNotificationCentre,它们可以在单元格选择时将数据从Homeviewcontroller 传递给"Information" ViewController

【讨论】:

  • 谢谢您,您能向我解释一下如何使您提供的功能正常工作吗?有什么我需要做的吗?或者我可以按原样使用该代码吗?
  • 更新了答案
  • 我尝试将其放入我的HomeViewController.swift 文件中,如下所示:import UIKit class HomeViewController: UIViewController, UITableViewDelegate { @IBOutlet weak var tableView: UITableView! func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) { self.tabBarController?.selectedIndex = 1 } } } ...但在第 9 行调用时出现错误“Extra argument 'animated'”
  • 为什么要多一个{},把这个{ self.tabBarController?.selectedIndex = 1 }改成`self.tabBarController?.selectedIndex = 1`。
  • 这似乎解决了它,但是当我导航到 HomeViewController 时,控制台出现错误:Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Light___Sound_App.HomeViewController 0x7f99bfe21e90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key staticDataSource.'
猜你喜欢
  • 2018-01-07
  • 2016-02-04
  • 2016-04-10
  • 2013-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-19
相关资源
最近更新 更多