gpt4 book ai didi

xcode - For 循环中的 UITextView 缺少参数

转载 作者:可可西里 更新时间:2023-11-01 01:42:28 24 4
gpt4 key购买 nike

Xcode 在调用 textShown1 = CustomTextView 行时抛出一个 missing argument for parameter textContainer。我很好奇为什么它只在 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)

}

最佳答案

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))

关于xcode - For 循环中的 UITextView 缺少参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28287336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com