我正在使用Swift 3来覆盖使用rootviewcontroller初始化我的导航控制器的init方法(并将rootviewcontroller委托设置为self)。但是,我收到以下错误:
调用中的参数标签不正确(具有'rootViewController:',预期 '编码器:')
class NavigationController: UINavigationController, RootViewControllerDelegate {
let rvc = RootViewController()
convenience init() {
self.init(rootViewController: rvc) // Incorrect argument label in call (have 'rootViewController:', expected 'coder:')
self.rvc.delegate = self
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
有人可以解释一下我做错了吗?我最初尝试使用
覆盖func init()
但Xcode最终将我转换为
方便init()
答案 0 :(得分:6)
init(rootViewController:)
在UINavigationController
中定义,NavigationController
是您super
类的超类。因此,您应该使用self
代替convenience init() {
super.init(rootViewController: rvc)
self.rvc.delegate = self
}
来引用它:
NavigationController
由于您在coder:
中定义了另一个初始值设定项,Xcode认为您正在尝试调用 初始值设定项。这就是为什么它告诉你把change-tags-for-resource
--resource-type <value>
--resource-id <value>
[--add-tags <value>]
[--remove-tag-keys <value>]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
作为参数标签。