passing the context to another method

Go To


What is the correct way of passing the drawing context to another method in the same class from drawRect() ?

do you just pass it like this?


or do you use the functions: UIGraphicsGetCurrentContext(); and CGContextRestoreGState(ctx); at the beginning and end of the function respectively ?

2012-04-04 18:37
by Ayrad


Well, a context that is passed to a function may not always be the same as the current context, so the best way would be like in your first example.

- (void)drawMoreStuff:(CGContextRef)context {

Depending on your function though, you would use the current context if you have a function like:

- (void)drawMoreStuffToCurrentContext {
2012-04-04 18:42
by lnafziger


I use blocks for that aim, this question and answer will give you enough about how to go. Especially accepted answer gives what you want.

2012-04-04 18:49
by ilhnctn
I'm not sure why you would use a block here... He just wants to call another function - lnafziger 2012-04-06 17:10