Jawbone / JBChartView

iOS-based charting library for both line and bar graphs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bar chart doesn't paint inside selected UITableViewCell

williamsjj opened this issue · comments

Been banging my head on this for a few days...paints fine when UITableViewCell is unselected:

graph_painting_unselected

However, as long as the cell is selected, the JBBarChartView disappears...every other part of the cell's contentView paints fine (including the chart's footerView):
graph_notpainting_onselect

init(style: UITableViewCellStyle, reuseIdentifier: String?, parentVC:ManageHistoryVC?) {
    self.activitySparkChart = JBBarChartView();
    self.activitySparkChartFooterVC = ActivityChartFooterViewController(parentChart:self.activitySparkChart);
    self.activitySparkChart.translatesAutoresizingMaskIntoConstraints = false;
...
    self.activitySparkChart.footerView = self.activitySparkChartFooterVC.view;
    self.activitySparkChartFooterVC.updateAxis(left: "", center: "", right: "");
    self.contentView.addSubview(self.activitySparkChart);
override func layoutSubviews() {
        super.layoutSubviews();

        self.activitySparkChartFooterVC.viewWillLayoutSubviews();
        self.activitySparkChart.reloadDataAnimated(true);
    }

Any thoughts on what might be causing this would be greatly appreciated. I've also tried forcing a reloadData of the chart inside of the UITableViewCell's setSelected and setHighlighted, to no avail.

We encountered this issue when we wrote our demo project "Spark Friends". Link here.

It happens because the table view cell automatically changes background color of all views inside content view for highlighted state.

There's a slew of solutions to the problem. Full stack thread here.

I recommend turning off cell selections (ie. UITableViewCellSelectionStyleNone) and overriding setHighlighted:animated: and/or setSelected:animated: to set the background of the cell manually.

It's a huge annoyance! Closing for now. Please defer questions to the stack thread if you can't fix it, or re-open if you really think it's limited to JBChartView.

Thanks Terry, I really appreciate it. I saw that StackOverflow thread but it was so focused on the background color not changing I didn't think it would apply to repainting of the contentView. But you're right, handling it by hand in setSelected/setHighlighted fixes the repainting issue.