简体   繁体   English

即使我清除了数组,iOS UITextViews数据仍然存在

[英]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.

相关问题 传递的数据模型输出为零,即使在调试中我在传递之前设置了 var - A passed data model is coming out as nil even though in debug I was the var get set before being passed 即使使用AppGroup,我的Iwatch也无法从ios App中保存数据 - My Iwatch does not get data saved from ios App even though I used AppGroup IOS:Firebase查询返回空数组,即使端点中有对象 - IOS: Firebase Query Returns Empty Array even though there are objects in the endpoint iOS-同时滚动两个UITextView - iOS - Scrolling two UITextViews simultaneously 为什么这些UITextViews中的背景不清晰? - Why aren't the backgrounds within these UITextViews clear? Swift iOS-即使存在有效数据,Firebase是否可能损坏数据并返回Nil值? - Swift iOS -Is it Possible For Firebase to Corrupt Data and Return a Nil Value Even Though Valid Data Exists? UITextViews在iOS 7中的UITableView链接检测错误中 - UITextViews in a UITableView link detection bug in iOS 7 带有自定义图像的 UIButton 仍然显示 titleLabel,即使我将其设置为空白 - Swift iOS - UIButton with custom image still shows titleLabel even though I set it to blank - Swift iOS 如何将数据从两个 UITextViews 保存到 UserDefaults - How to save data from two UITextViews to UserDefaults 即使我要求在后台更新位置,为什么我的iOS应用程序会被杀死? - Why does my iOS app get killed even though I ask for location updates in the background?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM