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