Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
The drawRect in UITextView does nothing. All the drawing is done by the NSLayoutManager. Every time you type something, the text system notifies the NSLayoutManager and the text is redrawn. But how does the layout manager knows when to draw the initial text or how does it detect that the view has loaded?

setNeedsDisplay doesn't do anything either.
 
The drawRect in UITextView does nothing. All the drawing is done by the NSLayoutManager. Every time you type something, the text system notifies the NSLayoutManager and the text is redrawn. But how does the layout manager knows when to draw the initial text or how does it detect that the view has loaded?

setNeedsDisplay doesn't do anything either.

UITextViews are automatically embedded in UIScrollViews.
If you look at the class documentation you see that UITextView has a textStorage, which is a subclass auf NSAttributedString.

If you modify the attributedString, the layoutmanager will notice triggers a relayout and will advice the UIScrollView to redraw the changed regions.

The view itself knows when it's part of a visible view hierarchy after being added as a subview.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.