Moving project from XIB/NIB to Storyboards - ios

I have a project that I originally started working on in Xcode 4. I then moved this project to Xcode 6. The project compiles and runs swimmingly. I then wanted to move this to use Storyboards.
Reading here and elsewhere I see people say they accomplished this by doing the following:
Create storyboard
Drag a viewcontroller onto the storyboard
Click on the white of the viewcontroller
Delete it Goto the original XIB and copy the entire view
Paste that into the viewcontroller on the new storyboard
Go into the appdelegate.m file and edit the didFinishLaunchingWithOptions section to look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
No errors in my code. Builds fine but instead of seeing the new Storyboard / ViewController, I just see a black screen. Im sure I am missing something somewhere but I cannot seem to find what it is.
If you would like to see my code, I have it here: https://github.com/martylavender/LittleToDoApp/tree/Storyboards
Thanks

You need to set your first view controller as the initial view controller in your storyboard.
You just need to check the is initial View Controller line on the right panel

I figured it out.
Looking at the build information of the project, I hadnt set the Main Interface to the MainStoryboard. That with the earlier suggestion fixed it!!
Thanks!!!

Related

How to remove "Failed to instantiate the default view controller" warning?

Within my storyboard I don't have any VC with the Is Initial View Controller checked as I am instantiating and setting the window.rootViewController programmatically within the app delegate.
My app is working perfectly however I want to remove the "Failed to instantiate the default view controller" message.
I found question regarding this on SO and the accepted answer stated that the warning will go away if the Main Storyboard File Base Name is removed from the info.plist (Programmatically set the initial view controller using Storyboards).
However my app does not have the Main Storyboard File Base Name entry in the info.plist, so is there something else I can do to remove this warning?
This is a similar question. Here the answers worked perfectly for me. Please check it out.
iOS 7 - Failing to instantiate default view controller
Select a random VC in your storyboard as the initial VC. This will cause the warning to go away and the option will be overridden by your code inn AppDelegate. This is the approach I use to remove the warning. Maybe more of a workaround, but it is simple and works great :-)

Load custom view instead of default view in iOS app

I have some problem in creating View(must open at start of app) in already existing project.
I have project from https://github.com/emysa341/Login-with-gmail-google-g--using-oath-2.0-protocol , when i run this project it directly goes to login page but i need to change that to home screen. i.e when i click on button in first view then it has to go to login page.
I tried creating .h,.m and .xib file and tried to load these files first as soon as app starts but i am not getting that.
Just tell me process "How to create .xib file in an existing project and make that xib(created by me,not default) to load first?". I googled but no perfect solution.I tried changing code in appdelegate.m but no use.
In this method of appDelegate add this line
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
YourViewController *yourViewController=[[YourViewController alloc]initWithNibName:#"YourViewController" bundle:nil];
self.navController=[[UINavigationController alloc]yourViewController];
self.window.rootViewController=self.navController;
[self.window makeKeyAndVisible];
return YES;
}
If you are using storyboards, you set the first view there. Just open the .storyboard file in Xcode, and there should be an arrow that is faded out on one end, and the head of the arrow should be pointing to a view controller. Just click-and-drag that arrow to the view controller you want to show first, and you should be good to go.
Alternatively (still in the .storyboard file), select a view controller and in the Attributes Inspector there is a checkbox for "Is Initial View Controller" - check that box for the view you want to show up first.

iOS Storyboard UIObject won't be displayed

I am quite new in iOS development and I just finished following a series of tutorias to finally start myself. I decided to start from a blank based project to understand all the links and definition that must be made to create a simple view based project.
So I created the storyboard, add a view in it, create a custom class to implement it, link the class to the view on the identity inspector. I also had to change the "application didFinishLaunchWithOptions" to be sure that my view was loaded correctly by simply removing all codes and leaving the "return YES;" like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
Then I added an UIButton in the ViewController.m that I created before and add it to the ViewController's view. When I start the simulator I can see and click the button.
Finally I added a button directly by the storyboard, link it to the ViewController.h but this time it won't display on the simulator. I added several labels, images,... , by the storyboard and none of them can be seen. I added the same content by coding it and it displays correctly this time. What am I missing here?
If I am doing it now it is because I want to be able to add a new UIViewController to any of my project in the future and being able to implement it both with code and the storyboard.
Your help would be much appreciated!
Thanks!
Antoine

In XCode 4.6 how do you create a brand new iOS application combining a tabbed main application with a navigation controller on one of the tabs?

I am trying to add a navigation controller inside a tab bar controller in a brand new non-storyboard (plain old nib) style.
I found this demo which assumes that XCode has a new project template called "Tab Bar Application". It doesn't. Now XCode 4.6 has "New Tabbed Application". Of course, Apple in their great wisdom has decided that I should not have a main window nib (.xib) and should have the tab bar controller and its pages coded for me in the app delegate instead of in a new-user-friendly NIB instantiated tab controller. I guess that's because it's more flexible that way, and you can write code to decide what tabs the user sees and what tabs they don't see. If I turn on Storyboards, then I guess I can do everything visually still.
I am deeply confused by the long and tortured history of XCode version differences, which affect the validity of existing questions on stackoverflow and demos elsewhere on the web, that reference different iOS versions, and different XCode versions, and make assumptions specific to versions of XCode and iOS that now appear to have changed, and which each rely on different choices with respect to the contents of your Main Nib File Base Name being set or not set.
I also find that it seems that pre-storyboard-Nibs and the complexities of combining various UIKit widgets and controllers has been a primary motivation behind the creation of storyboards.
I am working in a real non-storyboard nib-based application that appears to have been created before this change of heart at apple, and I can see that at startup a lot of unecessary views are created automatically by nib-instantiation and then deleted, in order to dynamically hide and show tabs on the tab bar controller. This appears to have been thought about a great deal at Apple, and they've changed the recommended practices implicitly by changing the way new applications are generated in XCode. I'm not questioning their wisdom, in fact I appreciate the change, but it's left me lost and confused.
Anyways, I'm just trying to put a navigation controller inside a tab in the main tab bar, and I already have an application that must have been started back when XCode used to generate a main window and generate a "Tab Bar Application" with a top level view that is a tabbed view, and the tab bar controller is nib instantiated. The demo above assumes as much.
Apple apparently famously never has provided a demo of this obvious combination of tab bar plus navigation controller. Or so I'm told. And the Apple Human Interface Guidelines apparently state (or used to state?) that it's better to put a navigation controller inside a tab bar than vice versa, and my question should be understood as wishing to comply with the HIG however possible, so I believe I'm asking about the recommended combination, not the discouraged combination.
Here's what I've tried so far:
Tried to follow this blog post, from circa 2009, which assumes things true about older versions of XCode that are no longer true.
Starting with a new tabbed application which XCode generated for me, with storyboards turned OFF, I have a root app delegate .m file that it generated for me that apparently creates at app-startup time, a Tab Bar Controller object completely in code, and which has no Main Window nib. The following code is entirely written by Apple, and I am wondering where (as a relatively new Cocoa developer) I'm supposed to break into this and place my new stuff, if I wanted to change one of the tabs to hav a nav bar and its associated UINavigationViewController:
-- This marker helps stackoverflow's busted markdown system not be confused --
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[RPDAFirstViewController alloc] initWithNibName:#"RPDAFirstViewController_iPhone" bundle:nil];
viewController2 = [[RPDASecondViewController alloc] initWithNibName:#"RPDASecondViewController_iPhone" bundle:nil];
} else {
viewController1 = [[RPDAFirstViewController alloc] initWithNibName:#"RPDAFirstViewController_iPad" bundle:nil];
viewController2 = [[RPDASecondViewController alloc] initWithNibName:#"RPDASecondViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
It now appears that what used to be possible without writing code (according to that 2009 example on the blog I linked to) is now done purely in code. I have read about 500 pages of "Programming iOS 5", worked for a few hundred hours on my first app, and tried a lot of demo applications but I'm still a relatively unseasoned Cocoa/iOS developer, and I believe part of my confusion over all this is the "controller and view" pattern, and its rules for combining them, both in code, and in nibs, are not entirely clear to me.
--
Update: You can has teh codez! In the interest of helping out future XCode-cocoa-iOS noobs like me, I have made a complete demo app and posted it on github here.
Screenshot:
I was as confused as you were when I did the same thing, but once you understand the structure you will find out that it is quite simple.
Basically, You want to create a UINavigationController with the RootViewController you want to display first:
[UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:theViewControllerYouWantToDisplayFirst];
Then just add this controller to the array for your tab buttons.
NSArray *tabs = [[NSArray alloc]
initWithObjects: navController, otherTab, etc];
Then, set your tabs using such array.
UITabBarController *rootController = [[UITabBarController alloc] init];
[rootController setViewControllers:tabs];
and add it to your tab controller to your window:
[self.window setRootViewController:rootController];
And that is it. I took me some time to realize the way things are structured. The Tab View controller just holds a bunch of ViewControllers, you just need to make one of those view controllers your NavigationController.
If you don't mind starting a new app to get the basics going, try this:
Create a Tabbed Application (or whatever it's called nowadays):
Then select the view you want to have embedded in a NavigationController.
Then go to Editor -> Embed -> in NavigationController like shown below:
Your result will look like this:
Cheers!
As explained in the first two answers (both correct), I add another method to come back to the original "Tabbed Application" template (maybe version 3 of XCode? I don't remember).
In this template you'll have a main xib file with, inside, your TabBarController.
You must start from the Empty Application template, then go through this steps:
Add a new file, User Interface, Application Xib. In this tutorial I'll assume you will name it "Application.xib"
Go to your AppDelegate.h file and change this line:
#property (strong, nonatomic) UIWindow *window;
adding IBOutlet:
#property (strong, nonatomic) IBOutlet UIWindow *window;
Go inside AppDelegate.m and change your applicationDidFinishLaunching method with this
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// delete all and leave only the return
return YES;
}
Go inside Application.xib, select "App Delegate" from the Objects Menu, and then in the identity inspector change the Class --> write AppDelegate (or your AppDelegate.h class name)
Always in Application.xib, right click again on App Delegate Object, you will see a "window" Outlet --> link it to the Window object in the Object inspector on the left
Now, come back to the project, go in supporting files, main.m and change the return line like this:
:
return UIApplicationMain(argc, argv, nil, nil);
then, go inside the main .plist file and add a key: right click, add, key, "Main Nib File Base Name", Type String, Value "Application" (without quotes, without .xib extension)
Ok, now you have an empty "old style" nib application. Now you can go again inside Application.xib, drag your TabBar and link it as the Window "root view controller" (right click on the Window, link the root view controller property).
Then, inside the tab bar, you can drag ViewControllers, Navigation controllers, ecc...
If you need other details or images write me
EDIT:
I uploaded a sample project if you want to look: http://www.lombax.it/documents/ManualTab.zip
Screenshot:
I had a working application that I wanted to place under one "leg" of a tabbed application. I wanted to develop other portions of the "bigger app" under the other tabs. I didn't want to use storyboards. That removed a good deal of the solutions I found. Most of the remaining solutions were developed using older versions of Xcode and they simply wouldn't work with the version of Xcode I downloaded in Feb of 2013.
I tried creating my own tabbed application - (starting with an "Empty Application") as some of the developers on this thread had used. I felt like I was getting close, but I simply couldn't get it to work.
There is an excellent tutorial on using a "Tabbed Application with a Navigation Controller" by Vishal Kurup.
With a minor modification (listed below) by following the video I was able to slip my existing application under the default "Tabbed Application" created by Xcode.
Create a TabBar Controller with a Navigation Controller + Detail View in Xcode 4.3
can be found at
http://www.youtube.com/watch?v=UMpNbCs4mr4
the only real change I had to make from the default "Tabbed Application" was in the AppDelegate.m:
the following code supplied by the selecting "Tabbed Application" wouldn't serve my purpose
self.tabBarController.viewControllers = #[viewController1, viewController2];
this did
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigation ,
viewController1 ,viewController2, viewController3, viewController4, nil];
A big thank you goes out to Mr Vishal Kurup.
He has made a number of quality videos on iOS development.

How to add a UISplitViewController to a window-based app

If I create a new project in Xcode 3 - a "Universal" window based project, I can't seem to instantiate the UISplitViewController outlet I am adding to the iPad's XIB.
Starting with a brand new "window-based" project, I select "Universal" from the drop down (iPhone, iPad, Universal). I then create an IBOutlet property in AppDelegate_iPad.h, synthesize the variable in the .m file and release it in the appropriate dealloc.
I open MainWindow_iPad.xib file and add a UISplitViewController object to it. I then connect the "splitViewController" outlet from AppDelegate_iPad to the UISplitViewController I just dragged onto the XIB.
Unfortunately, when I run this, splitViewController is never instantiated. Consequently, I can't add it to the window's view or set it as the window's root controller. I check this by putting a break point in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
to view the splitViewController ivar - but unfortunately, it is always 0x0. Is there some special step I am missing? I've compared my code to the split view controller template in Xcode and I can't see any differences.

Resources