Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ChartViewBase as the type and instantiating the chart later as a specific type #2338

Closed
pktrkts opened this issue Apr 8, 2017 · 7 comments

Comments

@pktrkts
Copy link

pktrkts commented Apr 8, 2017

Hi,

What I'm trying to do is cut down on the number of custom UIViews my codebase will have. I'm going to have either a bar graph, a line graph, or a pie chart in view controllers that are otherwise identical. I'm going to create at least one custom UIView (since there are several different kinds of things the charts will be displaying data for, I'll have 16 view controllers, but there seems to be no way around having so many view controllers without using a poor design). What I was wondering is, could I use ChartViewBase and then instantiate the type of graph later? This would save me from making three custom uiviews that are otherwise identical, aside from being different chart types (BarChartView, LineChartView, etc.) It would really be nice to know if this works before I spend an inordinate amount of time implementing it in the code. Thanks for your consideration of this matter.

Sincerely,
Sean

@pmairoldi
Copy link
Collaborator

Pass a property to your viewcontroller for which chart type you want and create it in code.

@liuxuan30
Copy link
Member

second agree, use the base class in your xib and create sub classes in code.

@pktrkts
Copy link
Author

pktrkts commented Apr 20, 2017

When I set the ChartViewBase object to a BarChartView type (myChart.chart = BarChartView() or myChart.chart = BarChartView(frame: myChart.chart.contentRect) ) it sets myChart.chart to nil. I don't know why it sets it to nil or what I'm doing wrong. Any ideas on how to get it so that it's not nil?

Thanks,
Sean

@liuxuan30
Copy link
Member

@pktrkts is your myChart.chart weak?

@pktrkts
Copy link
Author

pktrkts commented Apr 21, 2017

Yes it is. Is it not supposed to be?

@pktrkts
Copy link
Author

pktrkts commented Apr 21, 2017

Okay removing the "weak" keyword made the problem go away. Thank you!

@liuxuan30
Copy link
Member

you need to figure out why yourself, as this is a common mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants