1

I am using Daniel Gindi's Charts library.

I have a ViewController in my app that is a scrollview, and it is supposed to display 4 line charts on different axes (i.e they are in different UIViews), and because the lineCharts themselves are quite big, I put them in a ScrollView to ensure that the graphs can be seen clearly.

Before connecting the UIView to the ViewController, the app works fine. I could scroll the page as expected, and also the LineChartView looks fine, it just displays "No Data to Show"

However, I realised my app crashes after trying to debug my failing ViewController. I realised I could not even add the IBOutlet for the LineChartViews into my ViewController. I tried it with one and it gives an NSUnknownKeyException, and the problematic part of the code is the IBOutlet. I have made sure all my connections are clean, in fact I rebuilt the storyboard to make sure everything was fine and it still crashes when I establish an IBOutlet.

There isn't much code involved as it just involves establishing an IBOutlet with the relevant ViewController. I saw in another post that adding chart.translatesAutoresizingMaskIntoConstraints = false might help and it did not.

The error is:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key chiller1Trend.'

danaq
  • 117
  • 11
  • What is `chiller1Trend`? – RajeshKumar R Jul 26 '19 at 07:39
  • oh right! chiller1Trend is one of the IBOutlets of the LineChartView that I made. – danaq Jul 26 '19 at 07:40
  • Remove the `chiller1Trend` `IBOutlet` from the storyboard – RajeshKumar R Jul 26 '19 at 07:42
  • that's what I did, and that works. But i need to display information in the linecharts and to do that I have to add them as IBOutlets to put in data. All the connections are clean – danaq Jul 26 '19 at 07:43
  • Did you solve your problem by re-connecting the View with the outlet property? If not, it would be helpful if you could show a) the code of your view controller properties and b) all connections of the view (and the subviews) – Andreas Oetjen Jul 26 '19 at 10:53

1 Answers1

2

You cannot use chiller1trend as anIBOutlet and as a Cocoa binding key. You need to do one thing or the other, not both, because if you use bindings you don’t need that outlet. Thus, either remove that outlet from the view controller class code or select the UIControl to which chiller1trend is bound in the bindings inspector in your storyboard or xib file and delete that Cocoa binding. Do not forget to check if the module of your controller is also well set.

jvarela
  • 3,744
  • 1
  • 22
  • 43
  • sorry if they may be quite and amatuerish question but where can I find the cocoa bindings? – danaq Jul 26 '19 at 08:19
  • As I said: in the code inspector, which is normally to the right of the code editor. If you are using Xcode 10, I think the bindings inspector is the one before the last inspector – jvarela Jul 26 '19 at 08:23
  • The thing is, what I do is I ctrl drag the view to my ViewController to add the IBOutlet. Besides the IBOutlet(s) there are no other bindings attached to it. – danaq Jul 26 '19 at 08:30
  • 2
    Then I suggest that you check this question: https://stackoverflow.com/questions/3088059/xcode-how-to-fix-nsunknownkeyexception-reason-this-class-is-not-key-valu?rq=1 – jvarela Jul 26 '19 at 13:40
  • Thank you for the suggestion, but I looked at the same post before asking the question and none of the solutions worked in my case – danaq Jul 29 '19 at 01:36
  • 1
    Hey, I have finally figured out the error. It involves checking the checkbox that says Inherit From Target. Thanks for your help. – danaq Jul 29 '19 at 02:27
  • My error and solution was also the same as @danaq. Thanks @jvarela! The last little bit to check if the module of your controller is set tipped me off. – craft Jan 29 '20 at 17:59