Reputation: 1
I am new to iPhone programming and now facing problem with storyboard. I want to remove storyboard from application and call view controller from appDelegate
programmatically. How can I accomplish this?
Here is my code in appDelegate
:
FirstViewController *firstView = [[FirstViewController alloc] init];
self.window.rootViewController = signInView;
return YES;
Still its showing black screen. Please help me. Thanks.
Upvotes: 0
Views: 1111
Reputation:
Delete MainStoryBorad file from your project.
Delete MainStroryBoard Key from info.plist file.
Clear MainInterface option from Project setttings.
Create New UIViewController with XIB file named "MyViewController"
In your AppDelegate.h add @property for New Controller "MyViewController"
In your AppDelegate.m update didFinishLaunchingWithOptions method this way.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
Upvotes: 0
Reputation: 107
Please find the below link and Check with things.. 1. Info.plist or General Info -> Removing main Interface 2. Check with .xib connections -> Custom class is added, view connection in .xib
https://github.com/sunilhts/RemoveDefaultStoryBoard
Upvotes: 0
Reputation: 1498
I think it is better to use storyboards than xib if your application is not that much complicated with large number of UI View Controllers. If you want to remove storyboard from project and use nib to use with the development do the steps with this link:
http://www.wastedpotential.com/create-an-ios-app-without-storyboards-in-xcode-5/
Upvotes: 0
Reputation: 35783
Here are the steps how I am doing.
Create a Empty project or If you have already created no worries, just remove StoryBoard entry from plist as @trick suggested.
delete MainStoryBorad file from your project
Create New UIViewController with XIB file named "MyViewController"
In your AppDelegate.h add @property for New Controller "MyViewController"
In your AppDelegate.m update didFinishLaunchingWithOptions method this way.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
Upvotes: 0
Reputation: 211
Maybe you have to remove the Main Interface in your project settings.
Upvotes: 0
Reputation: 14063
Did you initialize the window and made it key?
Here is an implementation of one of my apps:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[DDHDemoViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
Upvotes: 0
Reputation: 6192
The reason it's showing a black screen is because there is nothing configured in your FirstViewController
class. Try setting firstView.view.backgroundColor = [UIColor greenColor];
right before the return YES'
and you'll see that the FirstViewController is in fact loading; it just doesn't have any configuration besides what you've done in the init
method of your FirstViewController
class.
Honestly, configuring ViewControllers outside of the storyboard is not fun for beginners. I don't know why you want to do it, but your alternatives are using .nibs or adding everything manually. I encourage you not to delete your storyboard, but if you must, your code is fine. Just delete the storyboard file, or better yet, just don't use it until you decide to come back to it because it's a better idea.
Upvotes: 0