UIViewController defined in a xib file doesn't load in the storyboard - ios

I'm trying to load a subclass of a UIViewController with its views defined in a xib file into a storyboard. Let's call it a NibViewController.
The point of this approach is to reuse the same ViewController in multiple screens of the app.
I know it's possible to do it manually in the code, but I'm looking for a solution in the storyboard. I've tried suggestions from other topics like this one, but nothing worked. The ViewController is correctly displayed in the simulator but not in the storyboard. Here is the code: https://github.com/srstanic/NibViewControllerInStoryboard
and here is the screenshot:
Am I mistaken to expect the contents of the NibViewController to appear in the storyboard?

Am I mistaken to expect the contents of the NibViewController to appear in the storyboard?
Yes, you are mistaken. Your app is working perfectly so you should stop worrying and just proceed.
By deleting the view from the view controller in the storyboard, you have specifically instructed the storyboard: "Do not make a view for this view controller. At runtime, the view should come from the xib file, not from you."
And that is exactly what does happen at runtime. So just design your interface in the xib file and all will be well.

Related

What is the storyboard equivalent to an M file

So I have been using objective C and XIB files to do iOS programming for a while. I am starting now to learn storyboards and I am having a hard time figuring out how to write code for the storyboard. For example I am making a view where a user inputs info. Using my old style I would make a m, h, and a xib file. Edit the xib, link the elements to their definitions in the H file and make an iboutlet so that I can use it in the M file.
Now I have made a storyboard and added elements, how can I actually reference the elements in code, and where do I even put the code?
You create a subclass of the UIViewController, UIView, etc... Jus exactly as you would have done with a XIB. Then you set the class in the desired object in the storyboard just as you would have done with a xib...
Once the class is set you can link selectors etc as you would have done with a XIB file.
Now I have made a storyboard and added elements, how can I actually reference the elements in code, and where do I even put the code?
It's exactly the same as with .xib files. You can think of a single storyboard file as a collection of .xib files. A single .xib file typically contained a view controller of some kind and a view graph; when you instantiated the view controller, the view controller and its view graph were read out of the .xib and turned into objects. It's largely the same with storyboards -- you still have .m and .h files for your view controller class, and you still use IBOutlets to connect elements in the storyboard to properties or instance variables in your view controller.
The main thing that's different is that a storyboard allows you to specify the transitions between view controllers, so that you no longer have to write the code that creates a new view controller and transitions to it.

Loading a custom view in a storyboard from a separated nib file

I've customized an UIView in its own .xib file in order to being able to reuse it in several scenes of my storyboard. It is only a view with no view controller behind. I'm trying to load it in the storyboard and to see it in Interface Builder in the scenes I want to place it, with no success. I've been looking for a way to do that and I didn't found a post with an answer that worked for me.
I'm using Xcode 6.3.2 and my app is targeting iOS 7 and above. Could somebody help me?
Thanks in advance
What I do is make a subclass of UIView with its xib (CustomView.h, CustomView.m and CustomView.xib). And add a UIView to your controller on storyboard. Then assign its class to your custom view class.
This works without loading custom xib via code. But you cannot see the subviews of your custom view on storyboard.

Copy and paste storyboard controller into xib file. Supported or not?

I want to refactor out a storyboard controller to a separate xib, for better reusablity.
The controller extends UITableViewController.
I can select the controller in the storyboard, hit Cmd-C, create an empty xib file using the New File wizard, and finally paste the controller into the xib.
It seems to work ok. The UI elements are there, the outlets are there, etc. It forgets the orientation and the size (portrait, Retina 4-inch), but I can easily set that in the properties pane to the right in xcode.
However when trying to use this xib I get a crash with error message:
loaded the "MyController" nib but the view outlet was not set.
When I try to connect Files Owner to the table view (which is the top view in a controller extended from UITableViewController), xcode won't let me connect them.
My question: Is it unsupported to copy-paste a controller from a storyboard to a xib?
You are most likely jamming a tableViewController into a nib and there is no outlet to hook the view to. When you do Ctl-C in the storyboard make sure you copy the UITable not the UITableViewController. If not you can try to manually create the outlet in the controller but you might have to jump through hoops to make it work.

How do I know which xib is the first one to load?

I am researching a huge Xcode project, how do I know which xib is the first xib be loaded by IOS?
In main.m, I can only know the main delegation file, but how to find the main.xib.
BTW, I search the {project}-info.plist, but found nothing.
Addtion, I know which file is the rootviewcontroller.
From your description the project doesn't use storyboard(s), so the initial window and root view controller are created by the app delegate. This may or may not use an XIB file (you'd need to check the implementation if the view controller class).

Using Storyboard how to interact with viewcontroller objects

I've reviewed many websites and youtube videos that have IOS 5 storyboarding information. Most of them are pretty basic and only describe how to get started with storyboarding and how to segue into other views. I'm interested in taking it a step further and actually adding custom code to the views contained within the storyboard.
Is the "normal" workflow when creating an IOS app using storyboard?
Create the layout of an app using storyboard (adding views and objects to those views).
Create viewcontroller files (.h and .m), one for each view contained within the storyboard.
Hook up the scenes from the storyboard with your own view controller subclasses by editing the "class" values in Identity Inspector.
I believe I followed those steps, but when I implemented step #3 above and ran my application, I was only able to see a black screen. The view I had created in storyboard wouldn't display.
You have the right steps. Make sure you create your .m and .h without a xib. Post your code for the view controller for your first view to get more help.
yes, this is the normal workflow. have you set the "initial viewcontroller? ?
see this image: http://dl.dropbox.com/u/31437518/Screen%20Shot%202012-01-24%20at%2012.29.34%20AM.png
It sounds like you made a storyboard file but it isn't being loaded.
Do you have the main storyboard setting in the target summary screen filled in?

Resources