Problem with loading UITableView in Navigation-based App [duplicate] - iphone

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.
In Navigation-based App, when i try to load another view which has got implemented UITableView using initWithNibName:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *detailsViewController = [[UIViewController alloc] initWithNibName:#"bloop2ViewController" bundle:nil];
[[self navigationController] pushViewController:detailsViewController animated:YES];
[detailsViewController release];
}
after clicking UITableView cell i get:
2009-06-13 11:44:41.089 Bloop[75227:20b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0xd446f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
2009-06-13 11:44:41.092 Bloop[75227:20b] Stack: (
807902715, 2429103675, 808061681, 810717848, 810716389, 816538544, 807805711, 816533170, 816541363, 815230552, 815224116, 815223834, 815217291, 815258907, 815254969, 815262662, 815243017, 815265053, 815242666, 11044, 815018240, 815005661, 810768858, 807687328, 807683624, 839142449, 839142646, 814752238, 9088, 8942
)
But when i disconnect UITableView in InterfaceBuilder, view is loaded without any problems (except there's no way to push data into it).
UITableView implementation is proper - i tried it in a fresh XCode project, and it worked just fine.

The error message says you are trying to set the property "tableView" on an object of type UIViewController, which it does not have. I am just guessing, but maybe you have a derived view controller in your nib file, that has the property tableView, but then you construct not your derived object, but a UIViewController. You should try:
MyTableViewController *detailsViewController = [[MyTableViewController alloc] initWithNibName:#"bloop2ViewController" bundle:nil];

I was getting this problem and the fix was to make sure both
I set the NIB name in the view controller beneath the tab bar in the main window xib, and
the class name was set in the sub-viewcontroller.
This page was helpful for me.

I just experienced this issue. In my case the cause was the implementation code for MyTableViewController was being excluded from the current build configuration. Hope that helps someone.

Yet another way this can bite you. I had tossed out the xib for a view and started over. No matter what I did, the view threw this exception on load. After pulling my hair out for several hours, I finally deleted the app from the simulator and that fixed it. Somehow the old xib wasn't being replaced on install.

After 2 hours on this i forgot to
#synthesize tableView = _tableView;
Hope it helps
Mário

Related

class is not key value coding-compliant for the key navigationBar

I have added a UINavigationbar and UIscrollView to UIView(SecondView).When I click a button in firstView it should take me to secondView.
On button click :
SecondView *secondview=[[SecondView alloc]initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController: secondview animated:NO]; //error at this line
[secondview release];
In the secondView.h
#property(nonatomic,retain)IBOutlet UINavigationBar *navigationBar;
#property(nonatomic,retain)IBOutlet UIScrollView *testscroll;
SecondView.m:
#synthesize navigationBar,testscroll;
But Im getting error like :
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: SecondView setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navigationBar.
My secondView.xib is like this :
Couldnot understand where Im going wrong?
This error generally comes when you have created an outlet in your xib and then by mistake (or knowingly) you have deleted that iboutlet object, or vice versa.
So check your xib's iboutlet connections carefully.
Check the spelling:
#property(nonatomic,retain)IBOutlet UINavigationBar *navigationBar;
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: SecondView setValue:forUndefinedKey:]: this class is not key
value coding-compliant for the key navigationbar.
Note the difference of navigationBar and navigationbar, it's case sensitive.
you can presenting ModelViweController With navigationbar like this way:-
SecondView *objSecondView = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:objSecondView];
// add navigation bar image at hear
UIImage *image = [UIImage imageNamed:#"nav_launcher.png"];
[navbar.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
navbar.navigationBar.tintColor=[UIColor whiteColor];
[self presentModalViewController:navbar animated:YES];
and you can Push One View to Another View like:-
SecondView *objSecondView =[[SecondView alloc]initWithNibName:#"SecondView" bundle:nil];
[self.navigationController pushViewController:objSecondView animated:YES];
NOTE
Some time its error occurs because of we are putting wrong Nib name at this line of code : initWithNibName:#"SecondView" bundle:nil];
UPDATE
no need to add navbar tin image at SecondViewcontroller you can add all stuff hear like barbuttonItem, tincolor , navigatin BackgroudnColor ect.
pushViewController: is used to push a UIViewController. It looks like SecondView is a UIView, not a UIViewController.
I solved it myself.
I was wrong with nothing.Everything was OK.
I have added a new view and made the same connections and got it.Don't know why this happens regularly in xcode.
If you face this problem again,
try to: select File's Owner then click on the "Connection Inspector" (upper on the top of right pane), you will see all the outlets. Look for any sign like this (!) you will find it on the small circle which indicates a missing outlet, all you have to do is linking it properly or remove the outlet.
For erroneous case Rakesh provided correct answer (outlet was deleted - need accurately check your xib's / storyboards) with small addition:
it might be also caused by renaming outlet by simply "Find&Replace". In such case the outlet is re-named everywhere in sources, but not in storyboard.
In such case make sure you accurately renamed the outlet in storyboards too, e.g.:
grep -r --include "*.storyboard" navigationBar .
Than everything looks to be ok: XCode caching your xib's, to fix the behavior:
clean build
remove app from device/simulator
restart the app
Restart simulator might be also necessary (for me never was required for device)
I think you have not connect some object to the File's Owner in that UIViewController's xib.
Check one time my friend.

View Navigation Issue - 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle

I'm new to programming in objective C so I have a feeling this is just something really stupid I'm doing or failing to do...
I have an iPhone app and am trying to navigate from one view to another. I hooked up a segue and when I call it, like this:
[self performSegueWithIdentifier:#"ShowPolicyInformation" sender:sender];
it works just fine. But now I want to pass a value to my new view, and from what I can tell I can't do that with a segue. So I setup some properties on it and am trying to navigate to it more manually:
PolicyInfoViewController *pol =[[PolicyInfoViewController alloc] initWithNibName:#"PolicyViewController" bundle:nil];
pol.PropertyOne=txtOne.text;
pol.strPropertyTwo=txtTwo.text;
[[self navigationController] pushViewController:pol animated:YES];
When I replace the performSeque code with the code above, it builds fine, but I get this error when I run it:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'MainMobileViewController''
When I search for help with this issue, all of the suggests that are shown talk about making sure the .xib file is named correctly....and here is where I'm completely lost, because I don't have any .xib files that I can see. I'm working with a storyboard and just drag/dropping the views onto it and connecting it to classes I create. So...what newbie mistake am I making? What am I missing? I am working with xCode 4.4, so is this just different code than what I'm finding in these searches? Any help or advice would be greatly appreciated.
You can perform this by using Story Board only and not having to have a separate nib file for the PolicyInfoViewController... It would probably easier for you to do it this way.
so in keeping the first line of code:
[self performSegueWithIdentifier:#"ShowPolicyInformation" sender:sender];
You would need to override this method to manipulate properties of the PolicyInfoViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"ShowPolicyInformation"])
{
PolicyInfoViewController *pol = segue.destinationViewController;
pol.PropertyOne=txtOne.text;
pol.strPropertyTwo=txtTwo.text;
}
}
So what is happening here? First bit of code you are telling the control to perform the particular segue from story board. Second bit you are telling control what to do when a particular segue is called.

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.

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.