I have been using iOS for the past couple of months and what i have been doing is when i Click Single View Application, a default View Controller would appear with an XIB.
But with iOS 7, the XIB don't seem to appear, rather the storyboard appears.
I have no idea how to work with Storyboard's. I have neither used them in the past nor do i want to use them in the near Future. Do i always need to go ahead with an empty view and then add the relevant ViewController's
Please let me know if i am doing something silly or is it the new iOS 7 default behavior.
I did try to get into more detail's but could not get relevant answers on Google as well.
Thank you.
Step 1 Create New Project
Step 2 Select "Single View Application" -> Next
Step 3 Set ProjectName and other settings -> Next
Step 4 Save Project at location -> create
Step 5 Select Project in Navigator Panel in Left
Step 6 "Remove Main.storyboard" file from project
Step 7 "Add New .xib file in Project"
Step 8 Set Main Interface to your .xib file in "General Tab" on right panel.
Step 9 Paste following code in didFinishLaunchingWithOptions method
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
For iOS 7 compliance the correct XIB you need to use is the interface builder document named: Application, as your primary nib.
Related
I am trying to create a new app with Singe View template but there is no xib or storyboard option to make my interface as xib file !!! why does Apple remove xib from iOS 7 ?!! How can I create application with xib interface files ?
Create a new project
Select Single View Application
Set ProjectName and other settings
Save Project at location
Select Project in Navigator Panel in Left
Remove Main.storyboard file from project
Add New .xib file in Project
Set Main Interface to your .xib file in "General Tab" on right panel.
Paste following code in didFinishLaunchingWithOptions method
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
[self.window makeKeyAndVisible];
Apple removed it because they just want to "force" everybody to use Storyboards, although from what I know, a big amount of people just don't find them useful.
I'm afraid you'll have to do it yourself, just create an empty app and set yourself the view.
Check an example:
http://www.appcoda.com/hello-world-app-using-xcode-5-xib/
Apple remove it from xcode 5 . you have only one option to choose storyboard.
if you want to xibs then remove storyboard after creating singleView application and add xib manually.
another option is to create application in xcode 4.6 or earliar version then run it on xcode 5.
I'm brand new in Xcode and have been able to scoot by with some fairly simple apps thanks to my previous programming experience, the Storyboard in Xcode, and most of all THIS WEBSITE.
One thing I haven't been able to figure out is how to make my app universal? The way I have my app set up is that it looks a lot like the iPhone home screen with pages and app icons. However, when I hit the little "Change to iPhone 5" button, 1) It only changes my FirstViewController and 2)My icons are all out of alignment.
Do I make another storyboard (If so, how?)? Do I make another view controller for each screen resolution? For either of those questions do I program a test to see which device I'm using and for it to choose the correct storyboard or ViewController? My app is currently set to universal, but I still haven't even been able to find the iPad resolution option for view controllers and stuff.
Please be as simplistic as you can. I have only been doing this for an extremely short time. Thanks for all your help both here and around this site!
So In order to get the iPad version working, follow these steps:
First go to your target settings, scroll down to "Deployment Info", and change it from iPhone to Universal
Next you will need to create a new Storyboard file. On the bar at the top go File>New>File and this thing should pop up:
After you have selected iOS>User Interface>Storyboard as shown above, click next and it will ask iPhone or iPad. After selecting iPad, the new file will be ready to map your interface for iPad. However, you need to make sure the app uses it. So go back to your target settings and scroll back down to "Deployment Info" and switch to iPad:
Set the "Main Interface" option to the name of your new storyboard file.
As for preparing for iPhone 5, that part can get a bit annoying. I find that the additional space is too small for any major additions but too large to be ignored easily. How you deal with it will vary greatly depending on what you app does. From what you described, with app icons like the iPhone screen, you will probably want to have an additional row of icons, just like the iOS. To do this, you can either manage it programatically or you may want to have seperate storyboards for iPhone 4 vs iPhone 5. If you want the separate storyboards, this question will have your solution.
To initialize storyboard:
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
UIViewController *initialViewController;
if (iOSDeviceScreenSize.height == 480)
{
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:#"iPhone4" bundle:nil];
// Instantiate the initial view controller object from the storyboard
initialViewController = [iPhone35Storyboard instantiateInitialViewController];
}
if (iOSDeviceScreenSize.height == 568)
{
// iPhone 5 and iPod Touch 5th generation: 4 inch screen
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:#"iPhone5" bundle:nil];
initialViewController = [iPhone4Storyboard instantiateInitialViewController];
}
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
return YES;
This question already has answers here:
Conditionally start at different places in storyboard from AppDelegate
(10 answers)
Closed 9 years ago.
Im looking for a way to change the starting view within the storyboard. I have 2 different views, one for a tutorial and the other one is the app itself. I want to load the tutorial the first time the app is loaded and next time it should just be the app itself. How can I do this with code?
Are you trying to do it from a nibfile or in the AppDelegate?
In the first case, just check the flag "Is Initial View Controller".
in the second you must put your controller as RootViewController, like this:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options{
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
MenuViewController *menu = [navController.storyboard instantiateViewControllerWithIdentifier:#"MenuController"];
CustomViewController *custom = [navController.storyboard instantiateViewControllerWithIdentifier:#"CustomController"];
// First item in array is bottom of stack, last item is top.
navController.viewControllers = [NSArray arrayWithObjects:menu, custom, nil];
[self.window makeKeyAndVisible];
return YES;
}
Check these links fir first time app launch First iPhone Launch and First Launch
When u find app is launching first time load or push ur tutorial ViewController else load your default View controller as per ur need.
A way to do it with less code is to create a third view controller, call it root view, which will always be the first to load, then inside this view you check
which view to load next, either the tutorial or the app view.
Give each view a storyboard ID
call the tutorial view: #"tutorialMainView"
and the app view: #"appMainView"
Then from within the root view you can load it as follows:
NSString *viewName = #"tutorialMainView";
UIViewController *tempView = [[UIStoryboard storyboardWithName:#"my_storyboard" bundle:nil] instantiateViewControllerWithIdentifier:viewName];
It's up to you what to do afterwards, either push it, or have it replace the current rootView (I recommend setting it as the new rootViewController)
1.Go to storyboard
2.click on th view you want to make first
look at this picture and set initial controller as it is in image
I'm a beginner leearning Xcode, and I created a simple single view application for a pretty useless card game (it's not even really a game).
What I want to know is is it possible to import my single view application into an application with storyboards without having to make a new project and retyping all of the code and connections?
Or is it possible to make a multiview application without storyboards, that I could continue off in the same project?
If so, can anyone direct me to a resource to do so? Thanks.
You can make a multiview application without using Storyboard.
Make a new UIViewController with a nib
Apple's example of presented a view controller programmatically
- (void)add:(id)sender {
// Create the root view controller for the navigation controller
// The new view controller configures a Cancel and Done button for the
// navigation bar.
RecipeAddViewController *addController = [[RecipeAddViewController alloc]
init];
// Configure the RecipeAddViewController. In this case, it reports any
// changes to a custom delegate object.
addController.delegate = self;
// Create the navigation controller and present it.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion: nil];
}
If you are using an nib though you would want to allocated as followed:
RecipeAddViewController *addController = [[RecipeAddViewController alloc]
initWithNibName:#"yourNibName" bundle: nil];
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW1
You can easily just copy your source and header files of choice to whichever project you like (beware of enabled/disabled ARC, though). Also, you can mix storyboards and nib files as you wish. Here's a little documentation on nibs that you might find interesting. Basically, you can init a UIViewController with it's nib file like this:
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
Yes, you can go with #Alex answer.
And you can also add "Storyboard" in your project.
Steps to add storyboard are as follows:-
1. Add new file => Click on "User Interface" tab on left side => Select storyboard => Choose Device type => and create. A blank storyboard file has been created.
2. Now, drag-drop a UIViewController from list of objects(right side) and reference it with your view controller class.
In the same way, you can add other views using storyboard and create multi-view app.
I'm wondering if someone could explain (or point me in the right direction)
where the code for instantiating UIWindow disappears to when NOT using storyboards? In the empty-application project template the window is created in application didFinishLaunnching... in your AppDelegate.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
However if using storyboards, the above code is omitted, though obviously UIApplication knows which window to start off with.
Where the application looks for the info.plist file to know which storyboard(s) to start off with.
I'm certain this is all well documented somewhere I just haven't found it. Read this Where is the UIWindow instantiated in an iPhone app? but not much help. I've been at iOS for awhile, just never had to mess with the initial startup of an app until now. Thanks
I think you meant 'where the code disappears to when you are using storyboards.'
The application loads the storyboard according to the "Main storyboard file base name" (UIMainStoryboardFile) key in your Info.plist, and from that storyboard it loads the view controller with the "Is initial view controller" toggle set.
Edit: As asked in the comments, the following code (similar to the initial loading in xib-based apps) will allow you to load and display a storyboard by name upon application launch:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"StoryboardName" bundle:nil];
UIViewController *viewController = [storyboard instantiateInitialViewController];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
While using storyboards, the storyboard to be loaded comes from your app's Info.plist file.
There will be a section in your Info.plist file with the key value pair like this:
<key>UIMainStoryboardFile</key>
<string>MainStoryboard</string>
In this case, MainStoryboard is the name of the default storyboard that is loaded.