Blank black screen after removing MainStoryboard - ios

I wanted to get rid of the storyboard and make everything in nib files. So I removed the main story board and coded the launch routine in the app delegate. I also deleted the storyboard name in the summary section of the app target so the complier won't complain. However, now nothing is shown when the app is launch, only a black blank screen. Is there away to fix this without creating a new non-storyboard project?
Here is the code in my app delegate..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MasterViewController *mainController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] init];
[navController pushViewController:mainController animated:YES];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}

Edit your Info.plist to indicate the main nib file and not a storyboard file. You'll need to change both the key (UIMainStoryboardFile to NSMainNibFile) and the associated value.

When you deleted the main story board you also deleted the StoryBoard Entry Point. To fix this, replace the StoryBoard Entry Point and you should get the desired display.
Thanks,
Rajat
StoryBoard Entry Point

Related

UIWindow in iOS8 doesn't rotate correctly

I need to load storyboard programmatically, in iOS7 the following code works:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // need to comment out in iOS8
self.window.backgroundColor = [UIColor cyanColor];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
But in iOS8 (XCode 6.1), the above code doesn't auto rotate correctly:
and
I need to comment out self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; to correct the auto rotation.
Any idea that first line makes what different?
Well, I find the answer from developer forum. Just remove the UIMainStoryboardFile key from app's information property list.
"Your application's information property list contains the UIMainStoryboardFile key but you are also manually creating a UIWindow with a storyboard loaded manually in your app delegate.
When the UIMainStoryboardFile key is present in the information property list, the system creates a UIWindow object with the initial view controller from the storyboard corresponding to the value of the UIMainStoryboardFile key prior to calling your app delegate. Your app delegate then repeats this process, determining which storyboard to load based on the screen size, and creating another UIWindow with the initial view controller from the storyboard.
The window created by the system, being the first window, receives orientation change notification first. Due to a change in iOS 8.1, the first window ends up blocking the second window (the one you created, the key window) from responding to the orientation change. From what I have discerned, this only happens if the first windows rootViewController's view is not loaded (the original window is never made visible). I'm clarifying the details with engineering and will log any needed bug reports myself.
The solution for your app is to remove the UIMainStoryboardFile and UIMainStoryboardFile~ipad keys from your app's information property list."

How to create an iOS project with a XIB in Xcode 6?

I'm trying to create a project in Objective-C language without storyboard with Xcode 6 Beta 5. I have tried and created a empty project but it didn't work as Xcode 5.
I have read this topic How to create project without story board in Xcode 6 - Swift but it didn't help me.
What do you mean it didn't work as Xcode 5? You can create empty project without storyboard and then add your own class with XIB like in Xcode 5:
File -> New -> File -> Cocoa Touch Class -> Set "Subclass of:" as (for example) UIViewController and check "Also create XIB file".
You first make a new "Single View" project. This starts out with a Storyboard, but as Xcode 6 has removed the option for creating an Empty project, we will just work with it from here.
You then create a new file for this project, go into the "User Interface" category and select "View". I would name it the same name as your original ViewController as it will replace the storyboard we are about to delete from the project.
Once the XIB is created, you will want to select it and set the "File's Owner" to point to the "ViewController" class that you want this XIB to link with. That is done by going into the Identity Inspector of the File's Owner of the Xib, and changing the default of NSObject to the class name of your view controller.
Once done with that, you want to go to the Connections Inspector to link the view of the File's Owner to the view of the XIB. Just click the little circle across from "view" and drag it over to your view to connect it. You should then have a connection between view and View.
Now the important parts. Go into your project Target, under the "General" tab. There is a subsection called "Deployment Info". In that subsection there is a field for "Main Interface". This field should be showing the name of the storyboard. You need to delete the value shown in this field, so that the Main Interface is left blank.
Then go into the App Delegate and set the root view controller of your window like you have been for previous versions of Xcode. Once that is done you should have a running app using your XIB, and you can delete your storyboard from the project without any adverse affects.
I don't know why people are down voting this as it is a legitimate question, so here is what you need to do:
Create an empty project, create a new view controller (File/New/File) - with XIB file if you need one, import the new view controller into your AppDelegate, and set this view controller as the root view controller.
AppDelegate.m:
#import "AppDelegate.h"
// import the view controller you want to be displayed first
#import "FirstViewController.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// create an instance of the view controller you want to be displayed first
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
// set it as the root view controller of the application's window
[self.window setRootViewController:firstViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Now, of course, if you wanted the create a tab bar or navigation controller, you would do this a bit differently, however this should be a good starting point for you.
AppDelegate.h
UINavigationController *nav;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
ViewController *ll=[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
nav=[[UINavigationController alloc]initWithRootViewController:ll];
[self.window setRootViewController:nav];
[nav setNavigationBarHidden:YES];
return YES;
}
It is very simple:
create empty application project
add to this project New File -> Objective-C class (with .xib file). My class is named "ViewController" :)
Now you must create UINavigationController in AppDelegate.h e.g.:
#property (strong, nonatomic) UINavigationController *navController;
than you must set your navcontroller in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
ViewController* homeViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
_navController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
self.navController.navigationBarHidden = YES;
self.window.rootViewController = self.navController;
return YES;
}
Thats all.

Why am I unable to change my initial view controller programmatically in my AppDelegate?

I'm following the advice of this question in order to define my initial view controller at runtime, instead of always being the same based off of the Storyboard property.
This is my didFinishLaunching method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *compactNavigationController = [mainStoryboard instantiateViewControllerWithIdentifier:#"CompactNavigationController"];
self.window.rootViewController = compactNavigationController;
[self.window makeKeyAndVisible];
CompactPostsViewController *controller = (CompactPostsViewController *)compactNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
And I've unchecked "Is Initial View Controller" in my Storyboard, and I've removed "Main" from the default Storyboard in my app's info.
But when I launch the app I get a completely black screen. What am I doing wrong?
Your window is nil because you never created it. You need to add this line,
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
The window is created for you when you have the "Main storyboard base name" entry in your info.plist, but if you remove that, then you have to create the window yourself.
check your linkings in your storyboard(by right click on the tableview controller).This happens mostly when you not linked your tableview controller properly.

Error "Application windows are expected to have a root view controller" (iOS)

I've created a blank iPhone app project and would like to show a full-screen advertisement during app launch.
I tried to install the ad by following this guideline: https://github.com/mopub/mopub-ios-sdk/wiki/Interstitial-Integration-For-iOS
That's what I've done finally:
Actually all codes are just copied from the previous link.
However, an error shows when app runs:
Application windows are expected to have a root view controller at the end of application launch
I think this error may probably related to the loadView method, because if I remove the loadView method, the error disappeared.
In fact, this error seems common as it can be easily searched on the internet, but I don't know how loadView is related to it, and how can it be solved in my case.
Any solutions? Thanks a lot.
You probably need to do this:
Add
#import "ViewController.h"
to the top of AppDelegate.m
And in AppDelegate.m, your application:didFinishLaunchingWithOptions: method should have some code like this.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ... Other code
// Override point for customization after application launch.
ViewController *viewController = [[ViewController alloc] init];
self.window.rootViewController = viewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
UIViewController *vc = [[UIViewController alloc] init];
[vc.view addSubview:self.tab_controller.view];
[self.window setRootViewController:vc];
OR
UIViewController *vc = [[UIViewController alloc] init];
[vc.view addSubview:yourClass.view];
[self.window setRootViewController:vc];
If you started with an empty template and added a storyboard, you need to do a couple of things:
You need to delete all the lines (except return statement) inside didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
In project settings ->General, select your storyboard as the main interface
Attached snapshot to help you
At the right side check there is one option under attribute inspector which asks to set as "is rootView controller"

AppDelegate window.rootViewController Property

I have a problem with my iOS app. It is based on storyboards. So to set the rootViewController property it should be enough to set the "Initial View Controller" property in Interface Builder and the MainInterface-Property in the project settings to the name of my storyboard. Still I always get the message "Application windows are expected to have a root view controller at the end of application launch".
I do several things in the applicationDidFinishLaunching section but even if everything except return YES; is commented out, I get the message.
How can I fix this warning? Or can I ignore it as everything works?
Thanks a lot.
Are you using an activity indicator in your app delegate or root view controller by chance? If so, it might be setting itself as the root. Move the display of the indicator to somewhere after your main views are set up.
Try this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
InitialViewController initial = [self.storyboard instantiateViewControllerWithIdentifier:#"STORYBOARDID"];
window.rootViewController = initial;
[window makeKeyAndVisible];
return YES;}

Resources