Load xib from Cocoapod in Storyboard - ios

I have a storyboard where I want to embed a viewcontroller in a containerview. The ViewController and its xib are in a cocoapod I made. Is it possible to embed a viewcontroller and its xib from a cocoapod in a storyboard containerview?
I know that if you delete the viewcontroller's view (in the storyboard) then the storyboard will try to load the xib with the same name as the viewcontroller. However, this isn't working. The app crashes when the viewcontroller's outlets aren't linked up. I can only assume it's because the xib is in my cocoapod.
I've checked that the names match and all the appropriate custom types are set in IB (like changing File's Owner from UIViewController to MyCustomViewController). I added the xib to "resource_bundles" in the podspec too.

Related

I have One storyboard with different/multiple UIViews and I want a ViewController for each UIView. Swift

I have one storyboard with different views, I do not want all the codes in ViewController.swift I would rather have a Swift for each UIView.
Is it possible? and how do I do?
Use UIContainerView instead of just UIView. When you drag a UIContainerView into your storyboard it'll automatically create a View. Just make a new Cocoa Touch Class file in your project. Make sure the file is put under UIViewController
Then click on the new View that was automatically generated, go to Properties, then select your new Swift file. This connects the View to the file.

Xib to Storyboard issue in copying

I recently migrated from Xibs to Storyboard in Xcode 6. To do this, I created a new controller in storyboard, deleted the view in storyboard, selected and copied the whole view hierarchy in controller's xib and pasted it to storyboard.
I had to manually remap outlets in storyboard and it works.
The problem is I can not see any of the views in the storyboard, and so can not add any new subviews. All I see is the name of the controller and thats it (see image).
How do I get around with 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.

calling xib inside the Storyboard

Can I call or integrate my existing xib files with their corresponding .h and .m to the Storyboard? I have around 6 xib files with their layout inside and i need to call them inside my new storyboard.
You can't call your xib files in a storyboard, but you can copy and paste any views from your xib to the storyboard, and change the class of any of your storyboard view controllers to the class of the controllers that owned your xibs.

Resources