ios - 当某些条件成立时显示 UITabBar

标签 ios swift xcode

我目前是 swift 编程语言和 Xcode 的初学者,我正在尝试制作一个基本的应用程序。

我想要实现的是,在执行检查以确保条件为真后,我的 ViewController 显示 UITabBar。

我首先有一个 UITableViewController,它检查附加数据库表中的所有标题并将它们存储在数组中。

然后,当我单击一个单元格时,将打开一个新 Controller ,该 Controller 使用数组索引路径中的名称并将其用作 View 标题。

然后我检查数组中的第一项是否等于 View 标题,这就是我需要帮助的地方。

我想创建一个选项卡栏(如图所示),仅当标题等于数组中的第一个条目时才显示。我已经完成了检查:

if (institutionConnected + " University" == (self.navigationItem.title!)) {
        print("You are connected to this institution")
        print("This is the first entry")
}

institutionConnected is a string variable which I assign the first item of the array too

我在这里有点不确定如何创建选项卡栏及其定位,因此我们将不胜感激。

此外,显然在其他没有标签栏的 View 上,标签栏将被隐藏,因此会有一些空白空间,所以关于如何使我的 tableView 填充页面以避免空白空间有什么想法吗?

This is the view with the tab bar
Table view which when clicked opens the view with the tab bar

我希望我已经解释过了,但如果需要,请索取更多信息!

提前致谢,

最佳答案

如果我正确理解你的问题,

我认为你应该首先创建一个TabBarViewController,然后将TabBarViewController与你的TableViewController连接起来。

在 TableViewController 中,您可以使用以下函数来隐藏或显示标签栏

override func viewWillAppear(_ animated: Bool) {
    self.tabBarController?.tabBar.isHidden = true
}

关于ios - 当某些条件成立时显示 UITabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39943729/

相关文章:

ios - 加密或部分加密核心数据数据库?

ios - 在后台 ios 应用程序中播放音乐

iPhone/iPad 应用程序未出现在 iPad 应用程序商店中

ios - 无法创建新的证书签名请求 (CSR)?

ios - 将 ViewController 中的函数传递给 GameOverScene.swift

ios - 容器 View Controller 应用程序在 Swift 中崩溃 NSInternalInconsistencyException?

ios - 使用 UITextView 占位符并且在重新输入时不清除文本

ios - "None of your accounts are a member of XXXXX"尝试设置应用程序组

swift - 解析 mLabs 和 Heroku 的迁移错误

ios - 修复通用的 Swift Crashlytics 错误