I originally asked this question. I had assumed that the reason for the slow load time of my custom view was because of layering multiple views on top of each other or perhaps because of some recursion problem. However, after cutting out more and more code to see what would make a difference, it came down to whether I had a UITextView
present or not. Because the apparent source of my problem is so different than what I was expecting in my first question, I decided to start a new question rather than adding a lengthy update to the old one.
I set up my test project with two view controllers. A button on the first view controller calls a show segue to the second view controller. The second view controller has my custom view on it. (Using the second view controller let me get a sense of how long it took to load the custom view.)
Custom view code:
import UIKit
@IBDesignable class UIMongolTextView: UIView {
var textView = UITextView() // key line
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect){
super.init(frame: frame)
}
}
As you can see, the only difference from a UIView
is that I added a UITextView
property. And it is this custom view that loads very slowly. Running the Allocations tool in Instruments I get the following results (a count of 997):
However, if I comment out the line
//var textView = UITextView()
then I the custom view loads very quickly and only has a count of 7.
What is going on here? Is it possible to use a UITextView
property in a custom view and avoid this slow load time?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…