XCode 6 beta 4方便初始化错误

时间:2015-03-25 13:23:12

标签: swift xcode6 beta

它说Could not find an overload for init that accepts the supplied arguments

class MyController: UIViewController {

    required init(coder aDecoder: NSCoder) {    
        super.init(coder: aDecoder)
    }

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

    convenience init() {
        self.init(nibName: "CreditOptionsView", bundle: nil)
    }

}

为什么呢? 它在XCode 6 beta 2中工作

1 个答案:

答案 0 :(得分:3)

我解决它写一个空功能的覆盖,我不知道为什么swift无法找到它。例如:

class MyController: UIViewController {

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?){
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }       

    convenience init() {
        self.init(nibName: "CreditOptionsView", bundle: nil)
    }

}

同样的事情发生在UINavigationController的便利初始化中,并解决了再次添加空override

class MyNavigationController: UINavigationController {

    override init(rootViewController: UIViewController) {
        super.init(rootViewController: rootViewController)
    }

    convenience init() {
        self.init(rootViewController: UIViewController())
    }
}