App Crashes When Connecting a MapKit View using IBOutlet - swift

When I add a MapKit View to my viewController using storyboards, the app runs as it should. The crash occurs as soon as I add an IBOutlet connection. The error I get is this Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7f9f36897080> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key managerDelivOverviewMapBG.' I've deleted and remade the connection a few times, but it keeps crashing whenever one is made. I have done this a few times in my app already, and this is the only place where I cannot add a connection to a MapView.
EDIT: For whatever reason, no fix I could find worked, so I attempted to move on and just not use a map view which is when I realized my problem wasn't with the map view at all, because no matter what connection I made to any element, the app still crashes, so I wound up deleting the whole view controller and remaking it, which although inelegant, solved the problem.

Is the ViewController Custom Class set correctly in the Storyboard?
Make sure you added it to the ViewController Custom Class and not to the View Custom Class.
Also, after changing it, make sure to delete the old #IBOutlet and add new ones.
You can also check all the outlets connected to the View Controller by right clicking it on the left panel of the storyboard.
If you see an yellow warning sign in any of your outlets it means that it lost the connection and you need to add it again.

Related

"this class is not key value coding-compliant for the key...."

for the past few days i keep on getting this error everytime i run a build in xCode:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x1dd4a1c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key playBtn.'
at the begining it was in something i have made.
than i deleted it and it was still there - in an object (like this playBtn here) that did not exist anymore.
and now - in every single app i am trying to debug.
if on my iphone or in the simulator - the same.
i just can't run anything now !!
*clean doesn't work ! *
what do i do? i can't work like this..
notice:
solved. it was a problem with the appdelegate.m
thanks for who helped.
Check your IBOutlet connections in your XIB
You said playBtn does not exists, so check if connection still exist for the same, They will show ! mark in place of dot in connections.
I bet that You've got your File's Owner stuff messed up in your xibs.One of your views is set up to be the playBtn of the the File's Owner. However, when it's time to unarchive the nib, the owner doesn't have an playBtn property, so the unarchiving is failing.
Two Things you can do :
1) Check your "Connections Inspector" tab for the view that's throwing the error.
Remove all the Outlet Connections and re-connect all the Outlets.
2)
GoodLuck !!!
The problem is that you are indirectly (presumably when one of your nibs is unpacked) calling -setValue:forKey: on your UIApplication.
You can reproduce this issue by creating a new empty iPhone project and adding the following line to your app delegate's -application:didFinishLaunchingWithOptions:.
[[UIApplication sharedApplication] setValue:[[UIButton alloc] init] forKey:#"playBtn"];
Without a backtrace or even a complete log, it's hard to be sure, but it looks quite likely that you are having the same issue that is described here.
I solved it.
it was a problem with the appdelegate.m with the uitabbar.
thanks for who helped and those who tried :)

iOS add rootViewController to window causes delegate not found error

I'm creating an application that first loads a settings screen which displays a series of text fields and labels asking the user for input. This is all working fine.
What I then want to do is once this data has been input, it comes up with the main application interface.
What is happening though is that when I'm telling the application delegate to load the main view, it says that the viewController isn't key value complaint for the key delegate.
The code I'm using to create the viewController is:
CustomViewController *viewController = [[CustomViewController alloc] initWithNibName:#"CustomViewController" bundle:nil];
self.window.rootViewController = viewController;
If anyone thinks that UIWindow doesn't have a rootViewController property, please check the documentation. That's what I did, and it does have one.
Any help with figuring this out would be greatly appreciated.
For those that like full debug info, this is what I get from xcode.
2011-06-18 15:03:15.474 Some App[15596:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CustomViewController 0x53368b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'
Thanks,
Matt.
Most likely you try to use delegate somewhere in your xib file, but it doesn't exist in your CustomViewController class.
Check the connections in your nib file and remove the one that connects to the non existing delegate.
The rootViewController property was only recently introduced and might not be available on devices running an older version of iOS.
You want to have a UINavigationController as the root view controller of your application and subsequent pages you simply push onto it. If you don't want animation, then do animate:NO. If you don't need a navigation bar, then hide that as well.
It is generally preferable to use one of the existing container view controllers over swapping them out yourself.

Works in iPhone Simulator, but not on Phone

So I have an app which runs fine on the simulator, but not on the actual device.
At runtime, it gives me the following error:
2010-12-05 19:58:32.006 Sports[4668:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView isEqualToString:]: unrecognized selector sent to instance 0x800800'
A bit about the structure: I have a Tab Bar Controller, the first view being a UINavigationController.
The view in there is a UITableView. One thing that may or may not be related is that if I do #synthesize tableView; in the table view controller, the table stays blank on both simulator and phone (but does not crash).
If I take that out, it loads the correct data on the simulator, and crashes on the phone.
Where should delegate/dataSource be linked to in the Interface Builder? I tried linking it to "View" to "File's Owner", and making a new "ViewController" and none of those worked.
Both the delegate and dataSource should be linked to File's Owner, which is the view controller class that declares the table view as an IBOutlet; this should be the same view controller that owns the nib file. Additionally, that view controller should be implement the UITableViewDelegate and UITableViewDataSource protocols.
Add that #synthesize line back in, (unless you're subclassing UITableViewController, as pointed out by grahamparks in the comments!) make sure those connections are right, and, finally, make sure you've declared an IBOutlet for the table view, and connected that properly between your class and interface builder.
Found it!
Turns out that there wasn't really a problem with this at all. The problem was that the date field in my database, when run on my phone was always zero/nil.
Why? Because the NSDate object created never initialized and stayed at nil.
Why?
Because my phone is in 24 hour time and did not parse the am and pm properly.
Lessons learned!
Run your app with NSZombieEnabled set to yes. See http://www.cocoadev.com/index.pl?NSZombieEnabled for an explanation about it and how to set it. I think what you will find is that the app will now throw an exception in the simulator telling you that you are sending a message to an object that has been released.
Based on the error message you are receiving, I expect the culprit is a NSString or NSMutableString object. If it is an NSString then warning, that NSString could be shared by several different objects so figuring out where the extra release is might be hard.
Never fear though, Instruments helps tremendously in this regard. Here is a link that explains how to use Instruments to find out exactly where your object is being retained and released so you can track down which release is inappropriate. http://www.markj.net/iphone-memory-debug-nszombie/
Good luck!

Adding UINavigationBar to a UITabBarController

Ok so I actually got to add UINavigationBar inside a UITabBarController using the following tutorial: http://twilloapp.blogspot.com/2009/03/how-to-embed-navigation-controller.html
But now the issue is that whenever I add a new button inside one of the views it just crashes.
For example:
In the first view called FirstViewController I added:
IBOutlet UIButton *test;
Than I also created:
- (IBAction) doSomething:(id)sender;
I hook up the test button with the UI in interface builder. But when I run i get:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x3b12e80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key test.'
Not sure what's going on with this.
Does anyone know of a solution?
Also, does anyone know where can I find good pre-built templates for these kinda apps so I can just start working rather than editing and setting things up.
Thanks
When you unarchive the nib file at runtime, it's going to invoke setTest:aButton on your controller, which will redirect to setValue:aButton forKey:#"test". Since it's throwing an exception that it doesn't know what the key #"test" means, chances are you forgot to put the #synthesize test; in your FirstViewController.m file.

iPhone app crashing with NSUnknownKeyException setValue:forUndefinedKey: [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
I'm writing my first iPhone app, so I haven't gotten around to figuring out much in the way of debugging.
Essentially my app displays an image and when touched plays a short sound.
When compiling and building the project in XCode, everything builds successfully, but when the app is run in the iPhone simulator, it crashes.
I get the following error:
Application Specific Information:
iPhone Simulator 1.0 (70), iPhone OS 2.0 (5A331)
*** Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<UIView 0x34efd0> setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key kramerImage.'
kramerImage here is the image I'm using for the background.
I'm not sure what NSUnknownKeyException means or why the class is not key value coding-compliant for the key.
(This isn't really iPhone specific - the same thing will happen in regular Cocoa).
NSUnknownKeyException is a common error when using Key-Value Coding to access a key that the object doesn't have.
The properties of most Cocoa objects can be accessing directly:
[#"hello world" length] // Objective-C 1.0
#"hello world".length // Objective-C 2.0
Or via Key-Value Coding:
[#"hello world" valueForKey:#"length"]
I would get an NSUnknownKeyException if I used the following line:
[#"hello world" valueForKey:#"purpleMonkeyDishwasher"]
because NSString does not have a property (key) called 'purpleMonkeyDishwasher'.
Something in your code is trying to set a value for the key 'kramerImage' on an UIView, which (apparently) doesn't support that key. If you're using Interface Builder, it might be something in your nib.
Find where 'kramerImage' is being used, and try to track it down from there.
Also when you rename a view, don't forget to delete the reference on File's Owner. It may also raise this error.
Here's one where you'll get this error - and how to fix it. I was getting it when loading a nib that just had a custom TableViewCell. I used IB to build a xib that just had the File's Owner, First Responder, and the TableViewCell. The TableViewCell just had 4 UILabels which matched up to a class with 4 IBOutlet UILabels called rootCell. I changed the class of the TableViewCell to be rootCell. It worked fine until a made a couple of changes and suddenly I was getting the setValue:forUndefinedKey: when I was just instantiating the class after loading it from a nib:
NSArray * nib = [[NSBundle mainBundle] loadNibNamed:#"rootCell-iPad" owner:self options:nil];
cell = [nib objectAtIndex:0];
It failed at the first line, when the nib was trying to load. After a while, I noticed that it was trying to match the IBOutlet Labels to the root controller, NOT the rootCell class! That was my tipoff. What I did wrong was to inadvertently change the File's Owner to rootCell class. When I changed it back to NSObject, then it didn't try to match up to the delegate (rootController) when loading. So, if you're doing the above, make File's Owner an NSObject, but make the UITableCell your desired class.
I had this situation and it turns out even after finding all instances of the variable and deleting them my app still crashed. Heres what happened... I created another instance of a variable from a textfield from my XIB into my viewController.h but I realized I didnt need it anymore and deleted it. It turns out my program saw that and kept trying to use it in the program so in the future if this happens to anywhere else just go into you XIB right-click on the button or textfield etc and delete any extra unused variables.
I had this same problem today. I didn't have the right class specified for the View Controller in my Navigation Controller. This will happen often if you fail to specify the correct class for your views in Interface Builder.
You'll also get invalid selector issues as well. Always check your Interface Builder classes and connections!
This is how i solved mine, in Interface builder right-click the View Controller, there should be an exclamation mark on the missing outlet or action method. Find and remove all the references and that solved it.
This happened because i deleted the action method in the .m file.
It seems you are doing
#interface MyFirstIphoneAppViewController : UIViewController<> {
UIImageView *InitialkramerImage;
}
#property(nonatomic,retain) IBOutlet UIImageView *InitialkramerImage;
Then after synthesizing that imageview, When you open "MyFirstIphoneAppViewController.xib" in Interface Builder, you are taking an Image View from Tool(menu)/Library den linking that outlet to the 'InitialkramerImage' from the Files Owner of "MyFirstIphoneAppViewController.xib". Then you saved the project. But after that you might change the name of the outlet variable "InitialkramerImage" to "kramerImage". So, after doing this
#interface MyFirstIphoneAppViewController : UIViewController<> {
UIImageView *kramerImage;
}
#property(nonatomic,retain) IBOutlet UIImageView *kramerImage;
and saving the project when you run it, There is no existance of the outlet of "InitialkramerImage" in the "MyFirstIphoneAppViewController.xib". So, when you run the project there will be no outlet referencing from Imageview to the 'kramerImage' and
"For displaying the view,
UIViewController will try to find the
outlet to "InitialkramerImage" which
is not existing."
So, It will throw the "NSUnknownKeyException".
You can check the missing outlet by
opening the nib(.xib) file then right
clicking on the 'Files Owner' of that.
If you have done this code somewhere else and had a zip/compressed file, try to extract it again. It may work I dont know why but I feel like it is an extraction issue.
or you can try to change the IBOutlet to kramerImage and bind it again in NIB.