I am trying to draw a graph which moves up and down depending on the value of a slider.
My graph is being drawn in a view which belongs to a custom class GraphView.
There is one ViewController for the project and the slider calls a method moveLine.
This has a property endXPoint which I have set such that:
endXPoint = mySlider.value
My problem is that I don’t know how to reference this value from inside the drawRect method of my GraphView.
I have tried creating a reference to GraphView in the ViewController and setting the property there but it does not work:
GraphView *myGraphView = (GraphView *)self.view;
myGraphView.endXPoint = mySlider.value;
You have to set a property for the GraphView class like that:
Then from the ViewController you set the GraphView variable like:
The last line ask GraphView to update the View, calling the drawRect method.
In the drawRect method you can use endXPoint directly because it is a class property.
This is the correct version: