I am writing an iOS app; no ARC and no storyboards.
I have a view controller inside Navigation controller. It supposed to have Table view and navigation button which pushes to second view.
This is the error I get:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ViewController" nib but the view outlet was not set.'
*** First throw call stack:
(0x1c8d012 0x10cae7e 0x1c8cdeb 0xf2f18 0xf3418 0xf3648 0xf3882 0x42a25 0x42dbf 0x42f55 0x4bf67 0x2a88 0xf7b7 0xfda7 0x10fab 0x22315 0x2324b 0x14cf8 0x1be8df9 0x1be8ad0 0x1c02bf5 0x1c02962 0x1c33bb6 0x1c32f44 0x1c32e1b 0x107da 0x1265c 0x2442 0x2375)
libc++abi.dylib: terminate called throwing an exception
(lldb)
The code in AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewCon = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
self.navCon = [[UINavigationController alloc]initWithRootViewController:self.viewCon];
self.navCon.navigationBar.tintColor= [UIColor greenColor];
self.viewCon.title= #"First View";
self.tblView = [[UITableView alloc] init];
NSMutableArray *viewArr=[[NSMutableArray alloc] init];
[viewArr addObject:self.navCon];
self.navBar = [[UINavigationBar alloc] init];
self.viewCon.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Second View" style:UIBarButtonSystemItemAdd target:self action:(nil)];
[self.window addSubview:self.navBar];
self.window.rootViewController = self.viewCon;
[self.window makeKeyAndVisible];
return YES;
}
At this stage I cannot run even the app. What might be the prob?
Best regards
loaded the "ViewController" nib but the view outlet was not set.
It seems you forgot to connect the view outlet of the view controller to your actual view in ViewController.xib file.
Your xib file has got a file's owner. This you have presumably set to be a ViewController (which I imagine is a subclass of UIViewController).
Now, if you go to the right-hand pane and show the bindings pane (the last one, with a small arrow), you will see that the view controller has got an outlet called view: drag from the small circle on its right on to the view which you have created in the xib.
Related
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xa46e6a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
I've been researching this for the past couple of days but I haven't found an answer that gets my app to run.
I have a universal app with two nib files (one for phone, one for pad) and no matter what I change I keep running into this runtime error. I have triple-checked my connections in the Interface Builder. I also defined the main interfaces for both phone and pad respectively.
This is what my AppDelegate.m looks like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ViewController *viewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
}else {
viewController = [[ViewController alloc] initWithNibName:#"ViewController-iPad" bundle:nil];
}
self.window.rootViewController = viewController;
[viewController release];
[self.window makeKeyAndVisible];
return YES;
}
I would like to suggest to check your xib files of ViewController.
Is the custom class of file's owner set to ViewController?
and view outlet connected to file's owner?
and then try it again.
I'm newbie. I'm trying to use UITabBarController with UITableViewController (without UINavigationController), but I've faced with exception after modifying std tabbar project
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UITableViewController
loadView] loaded the "IHHideView" nib but didn't get a UITableView.'
My didFinishLaunching
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *hideViewController = [[IHHideViewController alloc] init];
UIViewController *unhideViewController = [[IHUnhideViewController alloc] init];
UIViewController *filesVIewController = [[IHFilesViewController alloc] init];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[hideViewController,unhideViewController,filesVIewController];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
IHHideViewController just simplesubclass of UITableViewController
#interface IHHideViewController : UITableViewController
#end
As I know UITableViewController create own UITableView object with the correct dimensions and autoresize mask if not to specify nib file. Why such exception occurs?
It is because you are sub-classing a TableViewController. Instead change:
#interface IHHideViewController : UITableViewController
to:
#interface IHHideViewController : UIViewController
Hmmm recreating project using empty template solve problem.
First of all, I'm a beginner, so I might have my concepts wrong.
This is my code in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController = [[UIViewController alloc] initWithNibName:#"FirstView" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController: viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
The idea is to programmatically add UINavigationController, but then use a .xib (the "FirstView" paremeter) for the views. I have no problem with programmatically creating the views as well, but for simpler interfaces, I assume using IB can be done as well.
However, when I run the code, I get this error:
2013-07-11 21:20:42.644 new-book-proto-01[64308:11303] *** Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.'
What should I do? Is there anything missing?
Additionally, is something like this common in iOS development? Is it bad practice? Is there a better way to do this?
This is the reason as told: "reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.' "
It means that you try to access or get value for some views (UI elements) that has not IBOutlet in your controller class or you have none view at all
You should create IBOutlets (properties) for each view (each UI element is view) that you would like to "see" in your controller
I am facing crash with following code. The scenario is
This is my app delegate method in which i load RTC_HomeVC using UINavigationController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
RTC_HomeVC *obj_RTC_HomeVC=[[RTC_HomeVC alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:obj_RTC_HomeVC];
// Override point for customization after application launch.
self.window.rootViewController=nav;
[obj_RTC_HomeVC release];
[nav release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Now I want to open UINavigationController inside a parent Navigation controller. So i use a following code. The method -(IBAction)call_SectionFlow is in RTC_HomeVC.
-(IBAction)call_SectionFlow{
RTC_1_StoreDetailsVC *obj_StoreDetailsVC=[[RTC_1_StoreDetailsVC alloc]initWithNibName:#"RTC_1_StoreDetailsVC" bundle:nil];
RTC_3_EnablingWorksVC *obj_EnablingWorksVC = [[RTC_3_EnablingWorksVC alloc]initWithNibName:#"RTC_3_EnablingWorksVC" bundle:nil];
UINavigationController *navController_Sections = [[UINavigationController alloc] init];
NSArray *array_ControllerArray=[[NSArray alloc]initWithObjects:obj_StoreDetailsVC,obj_EnablingWorksVC, nil];
[navController_Sections setViewControllers:array_ControllerArray animated:FALSE]
navController_Sections.view.frame=CGRectMake(14, 40, 996,636 );
[self.view addSubview:[[[navController_Sections viewControllers] objectAtIndex:0] view]];
}
When i called this method application is crashed. This is crash log.
Crash log:
* Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:< RTC_1_StoreDetailsVC: 0x71f53a0 > should have parent view controller:< RTC_HomeVC: 0x758b310 > but actual parent is:< UINavigationController: 0x71f55d0 >'
* First throw call stack:
(0x1c9c012 0x10d9e7e 0x1c9bdeb 0x6838a 0x68739 0x6f5a3 0x67eed 0x4fc3 0x10ed705 0x24920 0x248b8 0xe5671 0xe5bcf 0xe4d38 0x5433f 0x54552 0x323aa 0x23cf8 0x1bf7df9 0x1bf7ad0 0x1c11bf5 0x1c11962 0x1c42bb6 0x1c41f44 0x1c41e1b 0x1bf67e3 0x1bf6668 0x2165c 0x1f82 0x1c45)
libc++abi.dylib: terminate called throwing an exception
So any one can tell me
What is wrong with this code? And which approach i should follow for resolving this crash ?
How to open another UINavigationController in existing UINavigationController?
Thanks.
Do not add subviews to UIWindow manually. It is not supported (or at least it does not work OK).
Use this method:
[firstNavigationVC presentViewController:secondNavigationVC animated:YES completion:nil];
What is causing crash is, that you are adding obj_StoreDetailsVC to the new navigation controller and then its view to self.view. Once a VC is child of another VC, its view must be descendant of that VC's view. Maybe you can add secondNavigationVC's view to to the view of firstNavigationVC, but that isn't how UIKit is supposed to work. Use the above method.
I'm trying to programatically create a UITabBar from a UIViewController. I am currently using this algorithm. However, I met up with a problem. May anyone tell me what I am lacking?
-(void)loadView{
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
TabControllerHelper *tabControllerHelper = [[TabControllerHelper alloc]initWithNibName:#"TabControllerHelper" bundle:[NSBundle mainBundle]];
tabControllerHelper.title = #"First";
TabControllerHelper *tabControllerHelper1 = [[TabControllerHelper alloc]initWithNibName:#"TabControllerHelper" bundle:nil];
tabControllerHelper1.title = #"Second";
//dvdInfoController.tabBarItem.image = [UIImage imageNamed:#"dvdicon.png"];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
// Set each tab to show an appropriate view controller
[tabBarController setViewControllers:[NSArray arrayWithObjects:tabControllerHelper, tabControllerHelper1, nil]];
[self.view addSubview:tabBarController.view];
}
The error I received:
2012-12-11 01:34:27.581 SampleUITabView[7134:c07] -[__NSCFType _tabBarItemClicked:]: unrecognized selector sent to instance 0x7574230
2012-12-11 01:34:27.582 SampleUITabView[7134:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType _tabBarItemClicked:]: unrecognized selector sent to instance 0x7574230'
*** First throw call stack:
You are doing some things which is "ViewController Containment". One approach could be to leave loadView alone and just let it do the basic stuff.
And in viewDidLoad do the view controller containment like
self addChildController ...
self.view addSubview:...
childController didMoveToParent ...
Because by just adding the tab bar controllers view as a subview, you are not necessarily getting the tabbar controllers behavior.