我想重用代碼,所以我創建redirectToTabBarControllerChild
斯威夫特:重用代碼傳遞類參數
func redirectToTabBarControllerChild(storyboardName: String, tabBarIndex: Int, segueID: String, viewController: UITableViewController) {
let storyboardMain = UIStoryboard(name: storyboardName, bundle: nil)
let tabBarController = storyboardMain.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
window?.rootViewController = tabBarController
tabBarController.selectedIndex = tabBarIndex
let navigationViewContrller = tabBarController.childViewControllers[tabBarIndex] as! UINavigationController
let currentViewContrller = navigationViewContrller.childViewControllers.first as! viewController
currentViewContrller.performSegue(withIdentifier: segueID, sender: nil)
window?.makeKeyAndVisible()
}
最後一個參數,我想傳遞ProfileViewController
例如。但我有一個錯誤在這行:let currentViewContrller = navigationViewContrller.childViewControllers.first as! viewController
Use of undeclared type viewController
有誰知道我怎麼能做到這一點?
,因爲它是一個對象,而不是一個類型。試試看'viewController.self'而不是 –