无法使用类型为“(字符串,选项:nil,指标:nil,视图:Dictionary<String,UIView!>)”的参数列表调用“constraintsWithVisualFormat”
Posted
技术标签:
【中文标题】无法使用类型为“(字符串,选项:nil,指标:nil,视图:Dictionary<String,UIView!>)”的参数列表调用“constraintsWithVisualFormat”【英文标题】:Cannot invoke 'constraintsWithVisualFormat' with an argument list of type '(String, options: nil, metrics: nil, views: Dictionary<String, UIView!>)' 【发布时间】:2015-07-08 16:25:04 【问题描述】:我在我的演示项目中编写了以下代码。
func createConstraints() -> Void
//Views to add constraints to
let views = Dictionary(dictionaryLiteral: ("red",vwRed),("blue",vwBlue),("green",vwGreen))
//Horizontal constraints
let horizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|[red]|", options: nil, metrics: nil, views: views)
self.view.addConstraints(horizontalConstraints)
//Vertical constraints
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|[red]|", options: nil, metrics: nil, views: views)
self.view.addConstraints(verticalConstraints)
其中 vwRed、vwBlue、vwGreen 定义如下
var vwBlue:UIView!
var vwRed:UIView!
var vwGreen:UIView!
现在我收到如下错误
我正在使用 Xcode 7-beta。
此外, 我还想提一下,它没有接受和给出错误。
//Prep auto layout
vwRed.setTranslatesAutoresizingMaskIntoConstraints(false)
vwBlue.setTranslatesAutoresizingMaskIntoConstraints(false)
vwGreen.setTranslatesAutoresizingMaskIntoConstraints(false)
我改成了
//Prep auto layout
vwRed.translatesAutoresizingMaskIntoConstraints = false
vwBlue.translatesAutoresizingMaskIntoConstraints = false
vwGreen.translatesAutoresizingMaskIntoConstraints = false
谢谢
【问题讨论】:
【参考方案1】:我将代码修改为下面的代码,它消除了编译器错误。这对你有用吗?
func createConstraints() -> Void
//Views to add constraints to
let views = Dictionary(dictionaryLiteral: ("red",vwRed),("blue",vwBlue),("green",vwGreen))
let horizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|[red]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
self.view.addConstraints(horizontalConstraints)
//Vertical constraints
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|[red]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
self.view.addConstraints(verticalConstraints)
【讨论】:
以上是关于无法使用类型为“(字符串,选项:nil,指标:nil,视图:Dictionary<String,UIView!>)”的参数列表调用“constraintsWithVisualFormat”的主要内容,如果未能解决你的问题,请参考以下文章
无法使用类型为“(UInt32)”的参数列表调用类型“CGBitmapInfo”的初始化程序