iOS - setValue:forUndefinedKey problem on a subView - ios

This looks like a basic IB error but it hasn't worked out to be.
*** Terminating app due to uncaught execption 'NSUnknownKeyExecption', reason:'[<TrailersViewController 0x585e8e0> setValue:forUndfinedKey:]: this class is not key value coding-compliant for the key myImageView.'
myImageView isn't in TrailersViewController it's in
another object that is on TrailersViewController.
myImageView does not have any IBOutlets.
Third it seems that you can have this problem when pushing view
controllers but it's object is shown in a subview.
myImageView is just a local variable in the object.
Also I had this working but noticed my TrailersViewController was rather leaky so I'm re-organizing it to stop those leaks.
I'm at a loss at the moment but any other directions I could head in would be awesome.

It seems like you have associated the myImageView view in the nib to a #property IBOutlet called myImageView inside TrailersViewController, but you have forgot to #synthesize this property.
So when the runtime tries to assign the myImageView object loaded from nib to the myImageView instance using key-value approach it doesn't find the setter method has you didn't synthesize it.

Related

App crashes when I add Charts UIView as IBOutlet to ViewController

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.'
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.

iOS xib file IBOutlet not recognized - (class not key-value coding compliant)

I am running XCode 7.1 and running on device(iOS 9) - (not simulator). I am loading up a nib file by name as such:
MyDetailsViewController *myDetailsVC = [MyDetailsViewController initWithNibNamed:#"MyDetails" withNotificationCenter:notificationCenter];
this is simply just a class method that i have set up that loads up the xib via the mainBundle. The xib file is just a UIView with a tableview inside of it everything seems to be hooked up properly. However, when loading the nib(viewWillAppear, viewDidLoad etc hasn't executed yet) from the bundle I get the error:
NSUnknownKeyException, reason: '[MyDetailsViewController setValue:forUndefinedKey:]:This class is not
key value coding-compliant for the key tableView'
I know that I am not getting back some generic view controller because it spells out very clearly what view controller we are talking about. The File Owner seems to be hooked up properly and its Custom Class is set to MyDetailsViewController. Even when I hover over the IBOutlet 'circle' in code the tableview highlights as well as when i hover over the menu when checking the outlets.
Something that may be totally unrelated is the internal error message in the xib file, it may or may not be related to my problem and i've never seen it before. The beginning of the log file that you get from that error is:
Can anyone help me determine what is going on here? I would appreciate it.
here are a few more screenshots:
Before init you should call alloc first:
// MyDetailsViewController *myDetailsVC = [MyDetailsViewController initWithNibNamed:#"MyDetails" withNotificationCenter:notificationCenter];
MyDetailsViewController *myDetailsVC = [[MyDetailsViewController alloc] initWithNibNamed:#"MyDetails" withNotificationCenter:notificationCenter];

Auto property synthesize will not synthesize property - new warning iOS8.3

After updating to iOS8.3 I started getting a bunch of new warnings that werent there on iOS8.2. One in particular that caught my eye;
#property (strong, nonatomic) IBOutlet UITableView *tableView;
which was declared in a '.m' file.
What has changed in iOS8.3 to make this a warning?
Auto property synthesis will not synthesize property 'tableView'; it will be implemented by its superclass, use #dynamic to acknowledge intention
If you're using a UITableViewController then tableView is already synthesized. (ie. self.tableView is the tableView of the UITableViewController).
I faced similar issue too. I solved this by the following method. Inside your .m file write #dynamic tableView under the #implementation
I hope your issue will be solved.
What has changed? The compiler has become more clever.
You are probably subclassing UITableViewController.
UITableViewController already has a property named tableView. It is already synthesized or implemented otherwise in UITableViewController. So the warning tells you that you are not getting your own tableView property, but that you are getting the one supplied by UITableViewController.
Obviously if you were not aware of the tableView in UITableViewController, and if you wrongly assumed that this is your property, under your control, there would be trouble. That's why you get a warning. So if that is what you were doing, then your code was always badly broken, and needs fixing.
But if you just have the #property declaration in your code, but you know that it is actually the UITableViewController property, no harm is done, but remove the #property because it is wrong.
Had a similar problem with a custom UITableViewCell creating a new property called imageView. Since a property named imageView already existed, I kept getting the error message. I simply changed the name to projectImageView and it worked.

Subclassing UICollectionViewLayoutAttributes

I recently started playing with the awesome UICollectionView API, making reasonable progress, but have been stuck for almost all day with an issue I'm hoping someone can help me with:
I need to add some custom details to certain cells' attributes.
In order to do this, the right approach seem to be to subclass UICollectionViewLayoutAttributes and add the properties I need to my subclass. So far so good, except that when I return my LayoutAttributesSubclass, I always get the, somehow obscure, following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
Having tried to track this down for a while, I'm under the impression that the error is related to representedElementKind and representedElementCategory being nil in my subclass's instance. But those properties are read only, so I can't set those.
I've managed to somehow bypass the error by cheating, getting a regular UICollectionViewAttributes instance, then changing it to a LayoutAttributesSubclass using object_setClass, but this then raises a ton of other issues, plus seems rather shady to me.
In short, does anyone knows what the error above means, and how to correctly create/use UICollectionViewLayoutAttributes subclasses?
When setting up custom attributes, you need to subclass UICollectionViewLayoutAttributes and subclass UICollectionViewLayout and "declare" your custom attribute subclass class name by overriding +(Class)layoutAttributesClass in your UICollectionViewLayout class. The system calls this class method to see if there is a custom class to be supplied when you use the factory method for instantiating/dequeuing layout attribute objects.
#interface YourCustomCollectionViewAttributes : UICollectionViewLayoutAttributes
#property (nonatomic) UIEdgeInsets myCustomProperty
#end
#interface YourCustomCollectionViewLayout : UICollectionViewLayout
#end
#implementation YourCustomCollectionViewLayout
+ (Class)layoutAttributesClass
{
return [IRTableCollectionViewLayoutAttributes class];
}
#end
This is correct according to the documentation and should prevent the particular error you are having. Also when you implement custom iVars, be sure to implement an override for -(id)copyWithZone: or the UICollectionView will lose any custom values you have applied to your custom collection view object.

How do I properly use the identifier property?

I want my program to be like this
if ([UIImageViewObject identifier]==#"heyItsMeYeaCoolDude")
{
do some methods
}
Whenever I do this though my programs crashes saying:
2012-07-29 19:09:58.401 Bridges[2711:f803] -[UIImageView identifier]: unrecognized selector sent to instance 0x8874f70
With a bunch of crap after it.
In my storyboard, I typed heyItsMeYeaCoolDude under label in the identity inspector, and now my program is complaining.
I know I could use tags also, but I'm already using my images tag for something else, help!
In response to the suggestion you made in the comment below your question, #ownageGuy, an answer to the question you pose:
You're welcome to subclass anything you like. Subclassing UIImageView is a perfectly acceptable solution to this problem. You might also consider the container pattern; ie. create a class which contains an instance of a UIImageView and an NSString for the identifier. Then even if there did happen to be a detriment to subclassing UIImageView, as you fear, it would be eliminated.
#interface UIImageViewContainer : NSObject
{
UIImageView* imgView;
NSString* identifier;
}
Then you create an object of type UIImageViewContainer, set imgView to the appropriate UIImageView, and store the identifier string inside identifier.

Resources