[英]self.tabBarController!.viewControllers returning nil
我有一個TabBarController,它連接了四個不同的UIViews。 TabBarController是從Controller.swift文件管理的,看起來像這樣
import UIKit
import Firebase
class Controller: UITabBarController {
var firebaseUser = String()
override func viewDidLoad() {
super.viewDidLoad()
//let allVC = self.tabBarController?.viewControllers
//let SearchVC = allVC![1] as! SearchVC
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
但是,被注釋掉的行會導致錯誤“...在解包可選時發現nil ..”(已經獲得allVC導致錯誤)
我該如何解決這個錯誤?
使用let allVC = self.viewControllers
因為您的類是UITabBarViewController
子類
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.