After launch I have a crash:
2015-11-13 17:47:50.744 app[18380:611105] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'Application windows are expected to have a root view controller at
the end of application launch'
I've read other questions with ios9 and root view controller and now my appdelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MainViewController *main = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow *window in windows) {
NSLog(#"window: %#",window.description);
if(window.rootViewController == nil){
UIViewController *vc = [[UIViewController alloc]initWithNibName:nil bundle:nil];
window.rootViewController = vc;
}
}
self.window.rootViewController = main;
[self.window setRootViewController:main];
[self.window makeKeyAndVisible];
return YES;
}
Unfortunately the problem is still there.
Maybe try getting rid of the loops:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor whiteColor];
MainViewController *main = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
window.rootViewController = main;
self.window = window;
[window makeKeyAndVisible];
return YES;
}
Related
In App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WalkThrough *viewControllers=[[WalkThrough alloc]init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewControllers];
[self.window setRootViewController:self.navigationController];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
navigationController.navigationBar.hidden = YES;
self.window.backgroundColor = [UIColor clearColor];
[self.window makeKeyAndVisible];
return YES;
}
Try to disable interactivePopGestureRecognizer after [window makeKeyAndVisible].
The key to the problem is that interactivePopGestureRecognizer property is nil until both two conditions are met:
the navigationController is associated to the window
the window become key and visible
after adding local notification script in "didFinishLaunchingWithOptions" it said
[1627:60b] Application windows are expected to have a root view
controller at the end of application launch
and this is the code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
mainStoryboard = nil;
if (IS_IPHONE_5) {
mainStoryboard = [UIStoryboard storyboardWithName:#"MainIPhone5" bundle:nil];
}
else {
mainStoryboard = [UIStoryboard storyboardWithName:#"MainIPhone" bundle:nil];
}
UILocalNotification *localNotification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
SelectedTask = [localNotification.userInfo objectForKey:#"FullTaskName"];
TaskViewController *TaskViewControllerVar;
TaskViewControllerVar = [mainStoryboard instantiateViewControllerWithIdentifier:#"TaskViewController"];
TaskViewControllerVar.SelectedTask = SelectedTask;
self.window.rootViewController = TaskViewControllerVar;
NSLog(#"1");
}else{
RecordingViewController *RecordingViewControllerVar;
RecordingViewControllerVar = [mainStoryboard instantiateViewControllerWithIdentifier:#"RecordingViewController"];
self.window.rootViewController = RecordingViewControllerVar;
NSLog(#"2");
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
return YES;
}
remove this line
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
you also need to add the views. Like this:
self.window.rootViewController = TaskViewControllerVar;
[self.window addSubview:TaskViewControllerVar.view];
and
self.window.rootViewController = RecordingViewControllerVar;
[self.window addSubview:RecordingViewControllerVar.view];
I try to push Viewcontroller it doesn't work.
AppDelegate.m (I import ViewController to use it as rootView)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
ViewController *view = [[ViewController alloc]init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:view];
return YES;
}
Next is my Viewcontroller.m
-(void)goToView{
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:#"newView" bundle:nil];
[self.navigationController pushViewController:view2 animated:YES];
}
I got error message:
Cannot find executable for CFBundle 0x8f9bd80</Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle>(not loaded)
2014-07-11 17:10:47.372 pushTest[2007:60b]***Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/home/Library/Application Support/iPhone Simulator/7.1/Applications/0D78CE53-F02B-467F-8250-8D2D3639A301/sta.app> (loaded)'with name 'newView'
This error can occure when you rename some files outside XCode. To solve it you can just remove the files from your project (Right Click - Delete and "Remove Reference") You re-import the files in your project and everything will be ok !
another choice
in your error code Could not load NIB in bundle means
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:#"newView" bundle:nil];
the Name newView does not match with bundle
just use this
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
in your app delegate.m add the valid Navigation controller
try this Navigation Controller Push View Controller
try this:
in AppDelegate
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
RootViewController *rvc = [mainStoryboard instantiateViewControllerWithIdentifier:#"RootViewController"];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:rvc];
self.window.rootViewController = nc;
in your Storyboard add a new ViewController with the storyBoard Identifier: "RootViewController".
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navc;
[_window addSubview:navc.view];
[self.window makeKeyAndVisible];
return YES;
}
Hope it helps.
Trying to write my first iPhone application using Xcode 5.1. Here is part of my AppDelegate code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"AddViewController"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.viewController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
I have a storyboard called "Main.Storyboard" with Navigation Controller and View Controller.
When I run my app I get SIGABRT error with NSInternalInconsistencyException exception.
Could anyone help me to fix this error?
Thanks.
why you adding subview as a UINavigationController.view and root-view as a view-controller? Your code must be look like this:-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"AddViewController"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
And verified that identifier of your viewcontroller is setting correct or not that you are given in above.
Try this
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyBord = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:[NSBundle mainBundle]];
self.window.rootViewController = [storyBord instantiateInitialViewController] ;
[self.window makeKeyAndVisible];
return YES;
}
If you use storyboard as a main interface you don't need to setup any code. So you can add UINavigationController to the scene in you storyboard. Then set rootViewController using connection inspector.
Check the video for understanding: link
the code will look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Here is the layout of my app.
ApplicationName
LoginViewController.h
LoginViewController.m
LoginView.xib
AppDelegate.h
AppDelegate.m
ViewController.h
ViewController.m
ViewController_iPhone.xib
ViewController_iPad.xib
Currently in my AppDelegate.m I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
LoginViewController *_loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginView" bundle:[NSBundle mainBundle]];
self.loginViewController = _loginViewController;
[_loginViewController release];
[_window addSubview:[loginViewController view]];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
} else {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
My LoginView.xib has it's File's Owner defined as LoginViewController.
I was at first getting an error stating: reason: '-[UITableViewController loadView] loaded the "LoginView" nib but didn't get a UITableView.'"
I changed UITableViewController to UIViewController and I was able to run the app without an error. The only problem now is that my LoginViewController does not load. I see the blank grey ViewController_iPad.xib loading.
What am I missing here?
I can post up any other code that would be useful.
Thanks in advance!
You should be setting your window's root view controller to self.loginViewController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginView" bundle:[NSBundle mainBundle]];
[self.loginViewController release];
self.window.rootViewController = self.loginViewController;
[self.window makeKeyAndVisible];
return YES;
}