[英]A passed data model is coming out as nil even though in debug I was the var get set before being passed
[英]iOS UITextViews data lingering even though I clear out an array
下圖顯示了UIViewController
Xcode圖形調試層次結構。 它看起來像我需要從破壞其他數據UITextViews
正在在數組編輯后重新UITextViews
。 每次進行更改時,都將UITextViews
數組設置為[],然后使用更新的數據重新創建它。 即使我確認確實將UITextView
數組重置為零元素,然后使用預期的元素數重新創建,這些幻影圖像仍在屏幕上徘徊,並且調試層次結構顯示未刪除某些內容。
我懷疑我需要做一些整理工作以查找和銷毀與UITextViews
相關的其他數據,並且將數組設置為零並不能清除子視圖中的所有內容,但是我不確定這可能是什么。 我希望對於那些有更多經驗的人來說,我的錯誤似乎很明顯,並且您會為我指明正確的方向。
我還在下面共享了一些代碼,但是我懷疑視覺效果可能是經驗豐富的人最直接的線索。
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
}
謝謝!
如果要從“ screenView”中刪除所有textView,僅清除數組是不夠的。 您需要將其從超級視圖中刪除:
screenView.subviews.forEach({ $0.removeFromSuperview() })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.