forcing a view to draw in cocoa
I have a superview and a subview. Both are custom. During the drawRect of the superview, I am trying to add 开发者_如何学编程the subview, create an image from the drawn view, and remove the subview.
My code works fine when I run it and start with the subview already drawn in the superview. It seems like adding the subview (during the drawRect) doesnt draw it immediately, it has to wait for the next drawRect.
How do I add a subview and force it to draw immediately?
First, if you find yourself forcing a display, you're almost certainly doing something wrong.
Second, you shouldn't be adding subviews during drawRect, which is meant mostly to draw the view's current State.
Third, what are you actually trying to do? The broad, dumbed down description, please. It seems to me you're having a problem with the basic approach to your goal, so if you describe it beyond the very narrow focus of what isn't working for you, we might be able to suggest a better (and perhaps easier) solution.
Finally, in direct answer to your question, just tell the view to -display if you want it to display immediately ... but I don't think it's going to behave the way you're expecting it to.
Use [view display] to immediately draw it.
精彩评论