Create storyboards that use XIB files - ios

I'm creating an app which includes a lot of re-usable views.
For this to work I created my main storyboard, and then the xib files for the re-usable views.
I then figured out a way to 'extract' the view from the xib file (drag the view out of the controller) which gave me the ability to freely resize the view in the xib file.
The outcome was that I had a bunch of custom sized views (xib's) and my main storyboard which would dynamically build lists from the xib files to use as sub views on it's main view.
Everything works perfectly in the simulator, but my question is, is it 'legal' to do it this way. Or would apple reject the app?
Thanks

Its ok to do so,Infact you can created custom sized views in storyboard itself but they will be embedded in viewcontroller anyway
Make the size to freeform in the attribute inspector of viewcontroller and you can have the customised sized view in viewcontroller itself

Related

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

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.

Share View between Storyboards

In android I would create a single layout and then use it with include in another layout xml file. Like this I can share single layout with multiple activity. Now in iOS XCode I want this approach to share single view created as .xib into multiple storyboards. I can see a View Controller but I don't know how to include view .xib under that View Controller. Any idea?
According to your Comment, you need to add that .xib view programmatically on your desired controller
e.g.
[ViewInWhichYouWantToAdd addSubview:xibController.view]

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.

IOS Custom UIView doesn't show

I'm sorry but i'm still a bit dumb in UIViews and creating a custom one.
I have a custom view and a xib file that are connected through the XIB IB.
I want to add this view to the storyboard.
What you see in this picture is an empty view which i've connected to the custom view class
When launching the app - i see the exact same view without my custom view being loaded.. what am i missing ?
It is not enough to just link your xib view to the storyboard through the view class name. You should copy the view from your xib (open your xib, select the root view and copy) to your storyboard view controller (select the parent view and paste). You can even open (double tap the xib file in the navigator) your xib in a new window and do a drag drop to the story board. Note that all the property wirings and constrains that you had defined in the xib will be retained when you copy paste your view from xib file.
The answer is actually pretty simple.
I had a recursive init process - meaning that although i did over initWithCoder method, in the xib file, i've set the view class to be my class.
What i should have done is to make my xib file's owner to be my class instead.
And then all the loadFromNibName worked perfectly in my initWithCoder!

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.

Resources