[swift]UITextView 在 For 循环中缺少参数

发布时间: 2015/6/10 0:55:48
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

投掷 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 也,但试图将其转换后它仍将引发错误。我改变了 CustomTextViewUITextView 只是为了有更令人困惑的代码:

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)

}

解决方法 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))
官方微信
官方QQ群
31647020