[英]iOS UITextViews data lingering even though I clear out an array
The image below shows Xcode graphical debug hierarchy for a UIViewController
. 下图显示了
UIViewController
Xcode图形调试层次结构。 It looks like I need to destroy additional data from UITextViews
that are being recreated after editing in an array of UITextViews
. 它看起来像我需要从破坏其他数据
UITextViews
正在在数组编辑后重新UITextViews
。 Each time I make a change, I've set the array of UITextViews
to [], then recreate it with the updated data. 每次进行更改时,都将
UITextViews
数组设置为[],然后使用更新的数据重新创建它。 Even though I verify that the UITextView
array is indeed being reset to zero elements, then recreated with the expected number of elements, these ghost images linger on screen and the debug hierarchy shows something isn't being removed. 即使我确认确实将
UITextView
数组重置为零元素,然后使用预期的元素数重新创建,这些幻影图像仍在屏幕上徘徊,并且调试层次结构显示未删除某些内容。
I suspect there's some sort of housekeeping I need to do to find & destroy additional data related to the UITextViews
, and that setting the array back to zero isn't clearing everything out of my subview, but I'm unsure what this might be. 我怀疑我需要做一些整理工作以查找和销毁与
UITextViews
相关的其他数据,并且将数组设置为零并不能清除子视图中的所有内容,但是我不确定这可能是什么。 I'm hopeful that my mistake seems obvious to those with more experience & you'll point me in the right direction. 我希望对于那些有更多经验的人来说,我的错误似乎很明显,并且您会为我指明正确的方向。
I also share some code below, but I suspect the visual may be the most direct clue for the experienced to set me straight. 我还在下面共享了一些代码,但是我怀疑视觉效果可能是经验丰富的人最直接的线索。
var topOfViewFrame: CGFloat = 0
textViewArray = []
for textBlock in textBlocks.textBlocksArray { // a textBlock has formatting data for a UITextView
let textBlockHeight = CGFloat(textBlock.numberOfLines) * textBlock.blockFontSize
let viewFrame = CGRect(x: 0, y: topOfViewFrame, width: textBoxWidth, height: textBlockHeight)
var newTextView = UITextView(frame: viewFrame)
newTextView.center = CGPoint(x: screenView.frame.width/2, y: topOfViewFrame + (textBlockHeight/2)) // screenView is the 320x240 subView holding the [UITextViews]
let viewFont = UIFont(name: "AvenirNextCondensed-Medium", size: textBlock.blockFontSize)
newTextView.font = viewFont
newTextView.text = textBlock.blockText
newTextView = configureTextBlockView(textBoxView: newTextView, textBlock: textBlock)
textViewArray.append(newTextView)
screenView.addSubview(newTextView) // screenView is the subview holding the [UITextViews]
topOfViewFrame += newTextView.frame.height // put the next UITextView directly below the previous one
}
Thanks! 谢谢!
If you want to remove all textViews from 'screenView' its not enough just to clear the array. 如果要从“ screenView”中删除所有textView,仅清除数组是不够的。 You need to remove it from superview:
您需要将其从超级视图中删除:
screenView.subviews.forEach({ $0.removeFromSuperview() })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.