调用中的参数标签不正确(有'frame:',期望'编码器:')

时间:2018-06-01 12:57:41

标签: ios iphone swift

它在UIView中工作但不在ViewController中,我收到此错误“调用中的参数标签不正确(有'frame:',期望'编码器:')”,如何解决这个问题。请检查附件图像

enter image description here

 init(frame: CGRect) {
    super.init(frame: frame)
    self.view.backgroundColor=UIColor.clear

    currentMonthIndex = Calendar.current.component(.month, from: Date()) - 1
    currentYear = Calendar.current.component(.year, from: Date())
    setupViews()
    btnLeft.isEnabled=true
}

super.init(frame:frame)我收到此行的错误

1 个答案:

答案 0 :(得分:3)

UIViewController不包含{init}仅适用于UIView元素

let myViewController = MyViewController( )

let myViewController = MyViewController(nibName: "MyViewController", bundle: nil)

//

class myViewController:UIViewController {

  // put here the properties 

    override func viewDidLoad() {
       super.viewDidLoad()
       self.view.backgroundColor=UIColor.clear
       currentMonthIndex = Calendar.current.component(.month, from: Date()) - 1
       currentYear = Calendar.current.component(.year, from: Date())
       setupViews()
       btnLeft.isEnabled=true
  }
}