简体   繁体   中英

iOS Contstraints Cause SIGABRT Error

I am making constraints with the visual language, but whenever I try to add them it causes an error.

class TimerViewController : UIViewController{
    let timer = TimerView()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        self.view.addSubview(timer)
        self.createContraints()
    }

    func createContraints(){
        self.timer.translatesAutoresizingMaskIntoConstraints = false
        let horizontalConstraints = 
NSLayoutConstraint.constraints(withVisualFormat: "H:|[timer]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["timer" : timer])
        let verticleContraints = 
NSLayoutConstraint.constraints(withVisualFormat: "V:|==[timer]==|", options: NSLayoutFormatOptions(), metrics: nil, views: ["timer" : timer])
        self.view.addConstraints(horizontalConstraints)
        self.view.addConstraints(verticleContraints)
    }
}

Xcode gives you the error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: 
Expected a view 
V:|==[timer]==| 
   ^'

So remove the == and it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM