Using NIBs in UIStoryboard - ios

For an ipad application in ioS5.0 using arc and storyboard, i wanted to create another custom view and instantiate several instances of that view within a scrollview so as to show a scrollable train of these custom views. To do this, I created the custom view in XIB file, however, how should I instantiate this view in the ViewController being refrenced within the storyboard. The custom view also has a gesture recogniser within it.
thank you in advance for your help on this.

I don't think there is a way to instantiate a nib backed view from a storyboard. You can do most of the layout in your storyboard, but then you will have to programmatically build your nib backed views and add them to the scroll view.
As a side note, it sounds like you are building something that could be solved with a UITableView and a prototype cell. Here is a pretty good tutorial.

Related

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.

How to create a separate view in Storyboard to be included programmatically in UITableView?

I have a UIViewController with a UITableView that is fed with data from the local database. When the user first launches the app (after installing) the table view is empty and I display a UIView in the middle of the table view that contains a UIImage, a UILabel and a UIButton (a call to action).
The first version of this view I built programmatically, which was no good to me because every time I tweaked something I had to build the app again. Then I switched to the storyboard but had to drag a UIView to the middle of my tableView. It is working now but I don't like the way it is, I can't edit my table view cells without having to move the UIView out of the table view.
I'd like to have a way to build this view entirely separated from my tableView (or even from my view controller in question) and then reference it in the viewDidLoad call of my view controller.
Unfortunately Xcode does not allow us to drag views directly to the storyboard so I'm pretty lost here.
Please tell me if I haven't been clear enough. I appreciate any help you could give me.
UPDATE: It'd be particularly awesome to me if I could also create a custom Swift class for this view of mine and reference it in the storyboard. And then in my viewDidLoad I could simply instantiate my custom view.
Thanks in advance.
Create a XIB file in which you can drag a view (without a view controller).
In your code you can load the XIB using NSBundle.mainBundle().loadNibNamed("MyXibName", owner:self, options:nil).
In the XIB file you can give the UIView a custom class (like you can do with view controllers in storyboard).
You then of course have to retrieve the view from the array returned by loadNibNamed and cast it to your custom class.

How to share the view layout of a view controller

Basically until now I create a ViewController in the Storyboard, set its class in the identity inspector and implement the connections and behaviour in the class.
Now I have two ViewControllers (ViewControllerFoo and ViewControllerBar), both are visually the same, but the information and the implementations of the actions of the buttons are different. So I want to create a BaseViewController, with the view creation and common implementation and override some methods in the ViewControllerFoo and ViewControllerBar
If possible I'd like to keep both ViewControllers in the StoryBoard in order to create the segues that launches each one of them visually
How can I do this?
Note: I'm starting with iOS development.
View layout is something that works with view not with view controller.
You can create a simple .xib (or view) file and draw your layout here.
After that add this view to controller or specify that view as main view of this controller.
Or you can create a view class and place all elements programmatically.
Just think about storyboard as 'navigation' utility not 'view layout' utility.
Note: too many views on storyboard speed down your computer and look too ugly.
Draw view in xib to reuse it or create custom views classes/clusters to implement interesting UX/UI effects

Swift add viewController as a subview to other views

I have multiple view controllers which should load a specific view like in this drawing. I defined that view in the storyboard as a separate view controller. The reusable view controller has some methods which make the view work. What's the best way to do this?
I tried using addSubview method but the IBOutlets won't initialize. Please help me.
You probably want to use a container view.
With a container view, you can embed different view controllers in the same view. Hooking them up is really easy, and can be done within the storyboard.

Use a Collectionviewcontroller on a view inside main view

In my IPad Application I have a main view and it contains three child views
top
middle
and bottom
Is it possible to use different view controller on different child views?
For Example i want to use collection view controller on the bottom view and top view.
if yes then is it possible to add and delete cells dynamicially? A small example would be appreciated.
If you are using iOS 6 you can create a container view controller easily in a storyboard by dropping ContainerView from the object library.
Otherwise you will need to implement a container view controller manually. See the documentation.
To Use a collection View Controller on a view first you have to create a UICollectionViewController with its CollectionView somewhere else. you can create this CollectionViewController in interface builder or programatically. then treat the collectionView of the UICollectionViewController as normal View and add it to your View with desired frame.
If you are not familiar with CollectionView then take a look at some Tutorial on UICollectionView on Google
UICollectionView tutorial

Resources