So the premise of my app is that it has multiple tabs and each tabViewController has a webView property that loads up a different webpage.
I'm not sure what exactly is wrong, and why it crashes.
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6a7c5b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key webView.'
The way I structured the app was I made separate ViewController classes for each tab. I included IBOutlets to the WebViews and linked them to webViews I included in the storyboard. I also set the CustomClass to the ViewController class.
Here is an example of my code (it's pretty much synonymous across the ViewControllers):
AmericaViewController.h
#import <UIKit/UIKit.h>
#interface AmericaViewController : UIViewController
#property (nonatomic, weak) IBOutlet UIWebView *webView;
#end
AmericaViewController.m
#import "AmericaViewController.h"
#implementation AmericaViewController
#synthesize webView = _webView;
-(void)viewDidLoad
{
[super viewDidLoad];
// allow user to pinch-zoom page
self.webView.scalesPageToFit = YES;
self.webView.multipleTouchEnabled = YES;
//load webView
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://baylornotes.org/articles/America"]]];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
#end
According to the exception, one of your UIViewController has no property webView.
Maybe one of your classes is not well written, or you forgot to set the right class in a xib...
Related
When running my app on the IOS simulator it just works fine, but if I run it on my device I get the next error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "XXXViewController" nib but didn't get a UITableView.'
Could this be a bug, as it is working in iOS simulator.
Does anyone know how to fix this?
I have setup my view controller as
#interface XXXViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
I have created the view programmatically, so there is no xib file (and no storyboard).
Adding
- (id)initWithStyle:(UITableViewStyle)style
{
return [self init];
}
solved the issue. as I was calling it in
-(id)init
{
// Call the superclass's designated initializer
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
...
}
return self;
}
Instead of:
#interface XXXViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
try:
#interface XXXViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
replace UITableViewController with UIViewController. Chances are that you have a UITableView and not a UITableViewController hence why you are explicitly setting up the delegate protocols in your .h file.
If you get other errors, please do let me know
I recently converted my .xib file to Storyboards and decided to programmatically add a UITableView to my ViewController in the storyboard.
I used this code to accomplish this:
// ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *table;
}
// ViewController.m
#import "ViewController.h"
#interface ViewController (PrivateStuff)
// unimportant code...
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
table = [[UITableView alloc] initWithFrame:self.view.bounds];
table.delegate = self;
table.dataSource = self;
[self.view addSubview:table];
}
Unfortunately, whenever I try to run it, Xcode is giving me this message...
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "ViewController" nib but didn't get a UITableView.'
... which doesn't make any sense. I have everything that needs to be hooked up on its correct order and all of my other views with UITableViews have no problem, in spite that the code is the same.
What could I do to solve this problem? Thanks in advance.
I agree with #rdelmar-Xcode is saying that a nib was loaded during a [tableviewcontroller loadView] call-so that means there is a tableviewcontroller somewhere in your code...but it also means that somehow the nib you created is still linked to your view controller. You may need to look at the connections inspector under utilities in Xcode and see if your nib still has any persistent links present and delete them. Otherwise, as long as you are providing a TableViewCell, either custom or generic, in the cellForRowAtIndexPath method, the above code should work
I am attempting to pass data back from one Table View Controller to the one before it. Here is the code I have written to accomplish it:
NPViewController.h (The second view passing data back):
#class NPViewController;
#protocol NPViewControllerDelegate <NSObject>
-(void) passItemBack: (NPViewController *) controller didFinishWithItem: (NSString *) string;
#end
#interface NPViewController : UITableViewController <UITextFieldDelegate>
#property (weak, nonatomic) id<NPViewControllerDelegate> delagate;
- (IBAction)createNewProject:(id)sender; //a bar button item that sends data on click
#end
NPViewController.m:
//barButton item IBAction
- (IBAction)createNewProject:(id)sender {
[self.delagate passItemBack:self didFinishWithItem:#"Test"];
[self dismissViewControllerAnimated:YES completion:nil];
}
InternalTabViewController.h //the first view to recieve data
#import <UIKit/UIKit.h>
#import "NPViewController.h"
#interface InternalTabViewController : UITableViewController <NPViewControllerDelegate>
#property (weak, nonatomic) NSString * projectName;
#property (weak, nonatomic) NSString * projectWorth;
#end
InternalTabViewController.m
#synthesize projectName, projectWorth;
//in ViewDidLoad
NPViewController *NPVC = [self.storyboard instantiateViewControllerWithIdentifier:#"NPViewController"];
NPVC.delagate = self;
//implementation of protocol function
-(void)passItemBack:(NPViewController *)controller didFinishWithItem:(NSString *)string
{
self.projectName = string;
}
The program cannot get past the first view controller (unrelated to these two) and throws the error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key createNewProject.'
I'm just trying to pass two strings back from one screen to another. How do I resolve this?
I cannot understand why you are passing NPViewController (ViewController) to InternalTabViewController(ViewController) and moment later you dismiss it ( dismissViewControllerAnimated).
As you need only string i would recommend redesigning protocol
-(void) passItemBack: (NPViewController *) controller didFinishWithItem: (NSString *) string;
to something simpler
-(void) passItemBack:(NSString*) item;
I don't know if it will solve problem. If I would have your full code I could help.
I have Xcode 4 and I created an application using the Tab Bar template (and not View based app). There is a UISwitch in each of these tabs and when I change it, a UILabel switches between ON and OFF. Very simple app and no confusion. Xcode 4 creates two tabs for me by default. I need a third tab as well, so I drag TabBarItem from the Objects Library and drop it on the existing TabBarController. I create a new file, subclass of UIViewController and the following code goes into three tabs.
The following is the interface
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController {
UISwitch *switch1;
UILabel *status1;
}
#property (nonatomic,retain) IBOutlet UISwitch *switch1;
#property (nonatomic,retain) IBOutlet UILabel *status1;
- (IBAction) switch1Change;
#end
The following is the implementation
#import "FirstViewController.h"
#implementation FirstViewController
#synthesize switch1;
#synthesize status1;
- (IBAction) switch1Change
{
if (switch1.on)
status1.text = #"ON";
else
status1.text = #"OFF";
}
The same code repeats for SecondViewController and ThirdViewController with ivars changing to switch2,status2 and switch3,status3. The link to the project is here
When I run it on the simulator, everything works fine for the first and second tab. When I open the third tab, I get the following error "Terminating app due to uncaught exception 'NSUnknownKeyException', reason: [ setValue: forUndefinedKey:]: this class is not key value coding-complaint for the key switch3."
When I remove the UISwitch from the ThirdView.xib, I don't get this error. Only when I add the switch control, I get this error. Can somebody please explain what is happening?
In Interface Builder, your third view controller is of class UIViewController (and doesn't have outlets for status3 or switch3). Change its class to ThirdViewController, wire up the outlets, and it should work.
when i try to build and run my app, it crashes and i got this in the log :
reason: '[<LoadingViewController 0x6b2c5a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aproposViewController.'
the strange is that aproposViewController is not used in LoadingViewController, it's just another view controller in my app. please help, thx in advance :)
EDIT
appdelegate.h :
#class LoadingViewController;
#interface TopStationAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate> {
UIWindow *window;
LoadingViewController *loadingView;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet LoadingViewController *loadingView;
#end
appdelegate.m :
#import "LoadingViewController.h"
#implementation TopStationAppDelegate
#synthesize window;
#synthesize loadingView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:loadingView.view];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[loadingView release];
[window release];
[super dealloc];
}
#end
there is no declaration of aproposViwController, even in IB for the main view !!
EDIT 2
here two screenshot of my besic set in the main and loadingView in interface builder :
Can't be sure if this is what's happening in your case, but you'll commonly see this message if you have a connection set up in your nibs to assign an object to a property of another object, but the property is missing on the target object.
So you might have had an IBOutlet named aproposViewController on LoadingViewController at one point, connected another view controller to it in the nib, and then removed the IBOutlet but neglected to remove the connection in the nib.
So when the nib is loaded, it tries to set the property, only to find it doesn't exist, hence:
reason: '[<LoadingViewController 0x6b2c5a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aproposViewController.'
I had this problem and it was because I had an:
vc = [[someVC alloc] initWithNibName:#"oldNibFileNameButCachedSomewhereWithOldRefToPropertyIn" bundle:nil];
If you removed the connection to IBOutlet from XIB and still it happens
Then delete the app from simulator and run again.
I have found the same error in my Application and I found solution for this after some time.
Actually I Have given 2 action events for one button.
I have removed extra connection which is assigned to button after that the problem is over.
This is worked in my scenario. I hope it will be helpful to someone else..