我真的很想知道如何快速更改标签栏项目的链接/目标 ViewController。
我的情况:
if (beforeDayX)
{
//TabBar[0] (Home) shows my1Scene with my1ViewController
} else
{
// TabBar[0] (Home) shows my2Scene with my2ViewController
}
我应该怎么做?可以吗?
最佳答案
注意:最初的答案是以编程方式创建 tabBar。但是由于 Josep(提问者)已经通过 Storyboard 创建了 tabBar,因此我在这里更改答案以满足需要。
假设:
(1) TabBar是使用UITabBarViewController创建的。类名:TabBarViewController
(2) Tabbar最初由WeekendVC、WeekdayVC、OtherVC组成。
(3) 根据条件,Tabbar 将变为:(WeekendVC 和 OtherVC)或(WeekdayVC 和 OtherVC)。
这是 TabBarViewController 的样子:
import UIKit
enum TypeOfDay {
case weekday
case weekend
}
class TabBarViewController: UITabBarController {
var typeOfDay: TypeOfDay = .weekday
override func viewDidLoad() {
super.viewDidLoad()
// Initial order is: WeekendVC, WeekdayVC, OtherVC
if let currentViewControllers = self.viewControllers {
let weekendVC = currentViewControllers[0]
let weekdayVC = currentViewControllers[1]
let otherVC = currentViewControllers[2]
switch typeOfDay {
case .weekend:
self.viewControllers = [weekendVC, otherVC]
case .weekday:
self.viewControllers = [weekdayVC, otherVC]
}
}
}
}
关于ios - 更改选项卡栏中选项卡的目标 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44192663/