I want to draw a chart in an UIView. The question is how do I get the data (Points) to the view. If I create a protocol and set the UIViewController as the delegate where in the UIView do I call the delegate methods (initWithFrame? might be to early, and the delegate might not be set, awakeFromNib? but the view is 100% created in code, it has no nib file) ..
I want to draw a chart in an UIView . The question is how
Share
In fact, the delegate cannot be set by the time you’re in
initWithFrame:, since the first thing you do with an object after allocation is initialization, i. e. until the init method returns, you can’t call (well, it’s idiomatic not to do so, at least) any other methods.What you have to do is have a
loadDataorreloadDatamethod, that the delegate must call explicitly after having set itself as the delegate of your view. I. e., from the view controller, you can call it like this:Then, in your chart drawing view, implement
- reloadDataas follows: