Xcode正在为missing argument for parameter textContainer
行投放textShown1 = CustomTextView
。我很好奇它为什么只在for
循环内抛出错误,但在它之外却没有。
for i in 1...paragraphCount {
// Missing 'argument textContainer in call below', various other errors like 'consuective statements on a line must be separated by ;'
textShown1 = CustomTextView(frame: CGRect(x: 0, y: 125 + (50*i)), width: CGRectGetWidth(self.frame), height: CGRectGetHeight(self.frame)-400))
paragraphs.append(textShown1)
self.view?.addSubview(textShown1)
}
textShown1 = CustomTextView(frame: CGRect(x: 0, y: 50, width: CGRectGetWidth(self.frame), height: CGRectGetHeight(self.frame)-400))
我认为它也可能导致问题不是CGFloat
,但在尝试转换它之后仍然会抛出错误。我将CustomTextView
更改为UITextView
只是为了让代码更容易混淆:
for i in 1...8 {
var converted: CGFloat = CGFloat(i)
// Missing 'argument textContainer in call below', various other errors like 'consuective statements on a line must be separated by ;'
textShown1 = UITextView(frame: CGRect(x: 0, y: (50 * converted)), width: CGRectGetWidth(self.frame), height: CGRectGetHeight(self.frame)-400)
paragraphs.append(textShown1)
self.view?.addSubview(textShown1)
}
答案 0 :(得分:1)
该错误具有误导性。您的问题是i
。这是一个Int
。您必须将其强制转换为CGFloat
才能使其正常运行。
var converted:CGFloat = CGFloat(i)
textShown1 = UITextView(frame: CGRectMake(0, 50 * converted, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) - CGFloat(400)))
答案 1 :(得分:1)
CGRect(x: 0, y: 125 + (50*i)), width: CGRectGetWidth(self.frame), height: CGRectGetHeight(self.frame)-400)
应该是
CGRectMake(0, CGFloat(125 + (50*i)), CGRectGetWidth(self.view.frame), CGFloat(CGRectGetHeight(self.view.frame)-400))