How to Call drawRect programmatically in objective c

S.P. picture S.P. · May 4, 2010 · Viewed 23.6k times · Source

How to Call drawRect programmatically in objective c ?

I want to call drawrect method of a view in my UItabbarcontroller. How i can do this ? Thanks in advance..

Edit

I have to call when the view is not visible currently. It will be the first time i have to call that view

Answer

JeremyP picture JeremyP · May 4, 2010
[myView.layer display];

Forces the view to draw itself straight away.

[myView setNeedsDisplay: YES];

Forces the view to redraw on the next event loop cycle.

However, if you need to call it even when it is not visible, I think there is something wrong with the design of your view class. You should only be doing drawing inside drawRect: not anything else. And if you are only doing drawing why do it when the view is not visible?