UICollectionView inside ViewController - ios

Good afternoon,
I would like to implement a UICollectionView inside my ViewController and I'm a little bit lost because I'm trying to read tutorials and find some good guides, but I'm unable to implement it.
I have a UICollectionView created in an another App, and it's using a UICollectionViewController, now I need to put that code inside a ViewController (without the UICollectionViewController), and it's hard for me because it's my first time implementing that view inside a ViewController.
Can you help me with some tutorial, guide or example? I want to know how to do this.
I have followed this tutorial to create the UICollectionView: http://www.techotopia.com/index.php/An_iOS_7_Storyboard-based_Collection_View_Tutorial#Adding_a_Collection_View_Controller_to_the_Storyboard and now I need to put that CollectionView in my "App" where it is going to show the user images, so in my top I'm going to have the username, userpicture, etc, etc and in the bottom I'm going to have the UICollectionView.
Thanks in advance.

In your storyboard, add a "Container View" to "ViewController". This adds a view to the view to the view controller and a "View Controller Scene" to your storyboard with a view controller at the end of "Storyboard Embed Segue". This view controller will control the content shown in the embedded view. Assign the "Custom Class" of the view controller at the end of the embed segue to be your collection view controller.
I am not at my iMac right now, so cannot supply screenshots. Give me a shout if you need them to understand what I trying to describe.

Related

Find the view controller for a UIView / set it to a different one

I apologize if this is a stupid question but I just can't seem to understand how the view controllers work in xcode. I added a view controller to my storyboard but when I try to add a button on it and a label that will be updated when that button is clicked, nothing is working. It will let me create an action for the button but the action won't do anything. It also won't let me add an outlet for the label so what I think is going on is that the view controller that I made isn't actually the one responsible view controller element on the storyboard (whose custom class is UIView and I can't change it the view controller that I made). The only other view controller file in the project also won't accept outlets for the label when I control drag from the storyboard so I really am not sure what is going on and how I can go about fixing it. Any and all help would be appreciated. I am really new to Swift so apologies again if this is a stupid question please bear with me.
Here is an image to help you. If you tap inside the controller it will take you to the view but if you tap on the controller it will take you to the UIViewController file.

Add UIPageControl to UIPageViewController via storyboard

I try to create onboarding page by following this tutorial and it works great.
That link suggest to create every page onboarding as single view controller using storyboard, then wrap it on my class which is subclass of UIPageViewController.
By following that tutorial, I already created nice onboarding page but there is one question remaining. Basically, I created each page of my onboarding pages using storyboard and create its class subclassing UIViewController. Then I dragged UIPageViewController which is my initial view controller. The result is created onboarding page that has black dot indicator on bottom page. I try to move that indicator and modify it, but still has no clue.
So my first step is remove implementation of its datasource method presentationCountForPageViewController and presentationIndexForPageViewController, my indicator has disappear.
My question is, where should I add UIPageControl so my onboarding page doesn't use its bottom indicator?
Any help would be appreciated. Thank you!
Subclass UIPageViewController is not the best idea. Better is to create a container view controller for UIPageViewController that will conform to UIPageViewControllerDataSource and UIPageViewControllerDelegate. Using storyboard you can add to you container view controller's view a container view that load your UIPageViewController. Get your UIPageViewController from -prepareForSegue:sender: method to configure.
Now you're able to manage your UIPageViewController from container view controller. Good luck!

iOS/Swift/Storyboard: Add PageViewController using only *part* of screen?

New to Swift. I've seen many tutorials on using PageViewController, but they always have the Page View taking up the whole screen.
I'm trying to implement a Page View functionality in only PART of my app, not the entire screen, so that other "static" elements (e.g. a ToolBar) can remain. Something that would look kinda like this...
https://imgur.com/9wM1vll --- (Need more rep. before embedding images)
...where swiping will cause different images to appear as seen in various PageViewController tutorials (e.g. http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/).
When I start with a Single View Application, I go to Storyboard and try to drag a "Page View Controller" from the Object Library into the ViewController frame, it just "bounces back", i.e. it won't let me add the Page View Controller.
Now, if I add the Page View Controller to the white space around the other View Controller, then this gets back to the tutorials where the PageViewController takes up the entire screen and I don't want that.
How does one achieve this?
Thanks.
Sorry if this is a dupe but I have tried & failed to find anything that answers my question directly. The closest are Implement PageViewController in TableViewController details or Adding a UIPageViewController to a subview, subview only shows edge of pageContentview, but these are not similar enough for me to comprehend, plus they're in Objective C which I've not yet learned.
When I start with a Single View Application, I go to Storyboard and try to drag a "Page View Controller" from the Object Library into the ViewController frame, it just "bounces back", i.e. it won't let me add the Page View Controller.
A page view controller is a view controller. Thus, to make its view occupy only part of the screen, you must obey the rules for view controllers in general: you need a custom parent view controller, and the page view controller must be its child view controller — and you must do the elaborate dance that this entails when you create the child and put its view into the interface.
To get the storyboard to do the dance for you, use a Container View and hook it by its embed segue to the page view controller:
(Still, in my opinion it is always better to learn to do the dance manually, in code, yourself.)

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.

Xcode storyboard UIWebView won't load

So all I want to do is create an App that has two pages: one with a button that opens up a UIWebView in the second. It seems simple enough, yet I have spent the past two days trying to figure it out.
I create the object and put in the code for the link and ctr - drag the web-view to the controlview.h but nothing will work.
Does anyone know a tutorial or can explain this to me? I have been searching the web for the pat two days and have gotten nowhere. thank you.
Each "page" should be a separate view controller. You open the storyboard editor, drag a view controller to it, drag a web view to your new view controller, then drag a segue from the appropriate control on the first page to the second page.
You will also need to create a UIViewController class for the second page, and set the controller's identity in the storyboard editor. (Select the second controller, type command-option-3, enter the view controller's class name in the "Custom Class" section.)
In the second view controller you will need some code to make the webview do something, obviously, so you probably will want to create an outlet for the webview.
Maybe you should start out with this general guide on View Controllers. You'll learn how to use View Controllers and how to present Modal View Controllers.
After that you go on with the documentation about UIWebView.
If you do a quick search for UIWebView you'll find tons of tutorials, but basics are important :)
CONTROL+DRAG does not work on storyboard. When I click view and drag to UIWebView, it opens a black popup but I cannot see my web value. I just see "view".
It does not work on storyboard either. I tried it on xib and it works with that.

Resources