从其类型初始化viewcontroller
我有视图控制器类型的列表。我想初始化它的相应类型。
struct TabbedViewControllers {
static var viewControllers: [UIViewController.Type] {
return [FeedViewController.self,
SearchViewController.self,
NotificationViewController.self,
ProfileViewController.self]
}
}
在这里,feedViewController
,searchViewController
,notificationViewController
,profile> profile> profile> profile> profile> profileviewcontroller
是UiviewController类型。
我正在创建一个自定义的TABBARCONTROLLERVIEWCONTROLLER类,其中我需要从TabbedViewControllers.viewControllers
property设置ViewControllers数组。
class TabBarControllerViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}
func setViewControllers() {
for vc in TabbedViewControllers.viewControllers {
self.viewControllers?.append(vc)
}
}
}
我正在汇编时间错误 - 无法将'uiviewController.type'类型的值转换为预期参数类型'uiviewController'
如何从其类型中初始化viewcontrollers。
谁能帮忙。
I have a list of view controller types. I want to initialize the corresponding types out of it.
struct TabbedViewControllers {
static var viewControllers: [UIViewController.Type] {
return [FeedViewController.self,
SearchViewController.self,
NotificationViewController.self,
ProfileViewController.self]
}
}
Here, FeedViewController
, SearchViewController
, NotificationViewController
, ProfileViewController
are UIViewController types.
I am creating a custom TabBarControllerViewController class where I need to set the viewControllers array from the TabbedViewControllers.viewControllers
property.
class TabBarControllerViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}
func setViewControllers() {
for vc in TabbedViewControllers.viewControllers {
self.viewControllers?.append(vc)
}
}
}
I am getting compile time error -Cannot convert value of type 'UIViewController.Type' to expected argument type 'UIViewController'
How to initialize viewControllers from its types.
Can anyone help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只是无法将UiviewController的 type 传递给tabbar。您需要将
uiviewController
的完全初始化对象传递给tabar,以使其工作。您可以简单地初始化uiviewController并传递对象
或使用故事板
You just can't pass
Type
of UIViewController to TabBar. You need to pass fully initialized object ofUIViewController
to TabBar for it to work.You can simply initialize your UIViewController and pass the object
Or if using a storyboard