views:

405

answers:

3

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

+2  A: 

setNeedsDisplay

ohho
Thanks for answer. But setNeedsDisplay will call only if the view is visible. In my condition view will not be visible. Sorry. my question was misleading. i have edited my question
Sijo
A: 

setNeedsDisplayInRect:

Williham Totland
+1  A: 
[myView 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?

JeremyP
There's a case where you do want to render it off screen, and that is when you intend to use the view's content (e.g. take a screenshot of it, or such) and cache or use it elsewhere. In my case, I want to take a screenshot of a view that isn't necessarily seen by the user and save that view's image to disk.
Kalle