views:

1044

answers:

2

I'm using an IBoutlet to get a reference to a Sub-View I added to the main View in the interface builder but since this won't give me access to drawRect: I won't be able to get a context to draw on. Is there anyway I can still get the graphics context so I can draw on the sub view? How would I go about this?

A: 

You can't draw like that; you have to draw in response to a drawRect call, not at any time as some frameworks allow.

The correct way to do it is: create a UIView subclass in Xcode. Switch to Interface Builder, select your subview, and change its "Class Identity" (under "Tools > Identity Inspector") to the name of your new subclass.

Then in your subclass, you can implement drawRect.

Adam Ernst
A: 

You should never be drawing in another view, not even a subview. The subview should draw itself, and it has access to its own graphics context. You cannot get access to another view's context; they are handled by the framework and are set up before calling -drawRect: for the appropriate view.

Rob Napier