I am using the open-sourced Charts
by Daniel Cohen Gindi: https://github.com/danielgindi/Charts
I have a pie chart on my screen which graphs itself like this:
//set pie chart data
graphView.data = PieChartData(dataSets: iPieChartDataSet)
Additionally I have a button on the screen which displays a popover similarly to the accepted answer of this question.
"What I Want"
When the user presses the UIButton
on the screen, I want a popover to display.
"What works"
When I press the UIButton
, the popover is created and presented as expected. Additionally I can create the popover, close it, and recreate it.
"What doesn't work"
If the graph is present on the screen, then the popover does not appear. I tried to using a print
statement within the UIButton
and it looks like the IBAction
is never fired.
Other information
Other UI actions work. I can tab to other tabs and I can swivel the graph around. It just seems that the UIButton
is somehow getting turned off if the graph on the screen is present.
Relevant code: How the popover is being created:
@IBAction func informationButtonTapped(_ sender: UIButton) {
var popoverContent = (self.storyboard?.instantiateViewController(withIdentifier: segueIdentifiers.informationPopover))! as UIViewController
var nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.popover
var popover = nav.popoverPresentationController
popoverContent.preferredContentSize = CGSize(width: 500,height: 600)
popover?.delegate = self
popover?.sourceView = self.view
popover?.sourceRect = CGRect(x: 0, y: 0, width: 100, height: 100)
self.present(nav, animated: true, completion: nil)
}
How the graph is being created (shortened as much as possible):
private func setChart(dataPoints: [String?], values: [Double]) {
var dataEntries: [PieChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = PieChartDataEntry(value: values[i], label: dataPoints[i])
dataEntries.append(dataEntry)
}
let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "")
var iPieChartDataSet: [IChartDataSet] = []
iPieChartDataSet.append(pieChartDataSet)
graphView.animate(xAxisDuration: 1.0, yAxisDuration: 1.0)
graphView.layer.borderWidth = 0.1
//set pie chart data
graphView.data = PieChartData(dataSets: iPieChartDataSet)
}