【问题标题】:Xcode: How can I change the "Default" Tab in a TabBarXcode:如何更改 TabBar 中的“默认”选项卡
【发布时间】:2020-04-07 08:35:55
【问题描述】:

我在MainStoryboard 中有一个带有TabBarController 的iOS 应用程序。选项卡栏工作正常,但我有 5 个选项卡,现在默认选择的选项卡是第一个选项卡,但我希望默认选择中间的选项卡(在这种情况下是第三个 --> 索引:2)。

我在堆栈overflow (Setting the default tab when using storyboards) 上找到了答案,但由于某种原因它对我不起作用。 我该如何管理呢?

提前感谢您!

【问题讨论】:

  • 这个问题有很多选项可以完成,你的 tababarcontroller 是 initilaviewcontroller 吗?
  • 你能添加你的代码吗?如果在设置 viewController 之前更改索引,它将不起作用。

标签: ios swift cocoa-touch


【解决方案1】:

设置 tabBarController 的 selectedIndex。

 var Launching = true
    override func viewWillAppear(animated: Bool) {
         if Launching == true {
             Launching = false
             self.tabBarController.selectedIndex = 2 // 3th tab
         }
    }

我希望它对你有用...... :)

【讨论】:

  • 我对 Apple 编码非常陌生。我应该把这段代码放在哪里?
  • 将此代码添加到您的 viewcontroller 的 swift 文件中
猜你喜欢
  • 1970-01-01
  • 2014-03-07
  • 2021-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-27
相关资源
最近更新 更多