在我的应用程序中,我试图做这样的事情:
class tabBarController : UITabBarController {
...
func example (){
let navController : UINavigationController = UINavigationController(rootViewController: calendarVC) //calendarVC is a UIViewController
guard var VCs = self.viewControllers as [UIViewController]? else{
self.setViewControllers([navController], animated: false)
return
}
self.setViewControllers(VCs.append(navController), animated: false)
}
...
}
但是在函数的最后一行我得到了一个错误:
Cannot convert value of type '()' to expected argument type '[UIViewController]?
我该如何解决这个问题?谢谢。
最佳答案
append
改变数组而不是返回一个添加了值的新数组。将你的最后一行分成 2:
VCs.append(navController)
self.setViewControllers(VCs, animated: false)
关于ios - 无法将类型 '()' 的值转换为预期的参数类型“[UIViewController]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32874256/