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

JBLineChartView: wrong width on iPhone6/6+ #177

Closed
va1da opened this issue Jul 13, 2015 · 9 comments
Closed

JBLineChartView: wrong width on iPhone6/6+ #177

va1da opened this issue Jul 13, 2015 · 9 comments

Comments

@va1da
Copy link

va1da commented Jul 13, 2015

I have JBLineChartView inside UITableViewCell which is inserted in UITableView after the touch on another UITableViewCell.
When the cell is displayed for the first time it has wrong width on iPhone6/6+. Later it look OK.
If I put ordinary UIView instead of JBLineChartView everything works fine.

Any idea what could be the reason?

Thanks.

bad
ok

@terryworona
Copy link
Collaborator

I'm guessing the width of the chart is incorrect when it's displayed the first time.

As an experiment, keep an instance around of the chart and call reloadData on viewDidAppear of your table controller. See what happens...

@va1da
Copy link
Author

va1da commented Jul 13, 2015

Unfortunately I can't because the big cell with the chart is made visible only after I select some row :-(

@va1da
Copy link
Author

va1da commented Jul 13, 2015

I've created a small sample which demonstrates the problem: https://dl.dropboxusercontent.com/u/102474509/ChartCellTest.zip

@terryworona
Copy link
Collaborator

I'm not super familiar with auto layout and constraints, but it seems that the chart's width is equal to 600 when the table is first loaded.

The property is found in IB:

screen shot 2015-07-13 at 9 55 56 am

@va1da
Copy link
Author

va1da commented Jul 13, 2015

AL constraints are set correctly, so it should work.
If you replace JBLineChartView with UIView it works OK.
So I think there must be something about JBLineChartView.

@terryworona
Copy link
Collaborator

Print out the chart's frame on reloadData and it's grabbing 600.

Subsequent call have it set to 375.

screen shot 2015-07-13 at 10 12 22 am

The chart is doing it's thing, it's just that reloadData is being called at a time where the chart's size isn't correctly set.

Why is it 600 to begin with? Any way to correct this and have it equal the width of the container?

@va1da
Copy link
Author

va1da commented Jul 13, 2015

I thought that AL should do it.
But I don't know how to make AL perform its calculations before reloadData is called :-(
I've tried to call layoutIfNeeded and layoutSubviews but it doesn't work.

@va1da
Copy link
Author

va1da commented Jul 13, 2015

OK finally I figured it out. I had to implement layoutSubviews:

- (void)layoutSubviews
{
    [super layoutSubviews];

    CGRect frame = self.contentView.frame;
    CGRect chartFrame = self.lineChartView.frame;
    chartFrame.size.width = frame.size.width;
    self.lineChartView.frame = chartFrame;
    [self.lineChartView reloadData];
}

Thanks a lot for your help.
JBChartView library is very nice!

@va1da va1da closed this as completed Jul 13, 2015
@ericcgu
Copy link

ericcgu commented Jul 13, 2015

Isn't it viewWillLayoutSubviews

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