How can I connect the text and the view so that every time I press the button, the text is drawn to the view?
Views do their own drawing.
You need to give the view the string to draw, and then set the view as needing display. You'll do these in the action method that you wire the button up to.
First, your custom view class needs to have a property for the value (string, in this case) that it's going to display. From your action method, which should generally be on a controller object, send the view object a setFoo:
message (assuming you named the property foo
). That takes care of job one: The view now has the value to display.
Job two is even easier: Send the view a setNeedsDisplay:
message, with the value YES
.
That's it. The action method is two lines.
Of course, since views draw themselves, you also need your custom view to actually draw, so you need to implement the drawRect:
method in that class. It, too, will be short; all you need to do is tell the string to draw itself.