Add UIPageControl to UIPageViewController via storyboard - ios

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!

Related

Pushing detail controller from cell of programatically created UITableView inside another view controller

I have a custom UIViewController that we'll just call ViewController. I'm using this library to have a view controller effect where one can slide left and right between pages. My pages are a programmatically created UITableView subclass. To be more specific, each page is a Day and the title of the page is the day of the week, and the cells in the UITableView subclass are events for that day.
I want to push to a new view controller when I touch one of these cells but I'm stuck. I want to push to a view controller that I've created in my storyboard and pass an object through that push that populates the view controller. My navigation controller I use in ViewController is created in storyboard. The custom UITableView is created programmatically.
Some errors I've been getting:
-- Application tried to push a nil view controller on target .
-- And also self.navigationController is nil.
I have no idea how to do this and there doesn't seem to be any helpful answer out there. I'm completely stuck. I've attached an image of my ViewController, and if you check out the linked GitHub repo you can see how I'm using the provided code there.
I figured it out using a delegate. I pass a delegate in my subclass UITableView back to my original ViewController. In my case it was an object. Check out this link:
How do I set up a simple delegate to communicate between two view controllers?

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.)

UICollectionView inside ViewController

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.

UIView vs Container View

So here is the problem I am trying to solve.
In each viewController I am trying to insert ads and the actual control elements. I finished couple of tutorial on raywenderlinch.com to understand that how people professionally put ads in their app. They used UIViews to have two views under mainview of view controller. So I completely understood that one subview hold the ads and another is holding actual app contents. if Ad is loaded take up the screen or else let other view have all available area.
After I came back to xcode I started coding the way I learned there. but when I was dropping UIView on storyboard, I saw containerView, which I think was not present when the tutorial was written.
So I am here to ask about the both approach and their pros and cons.
So basically its UIView vs ContainerView. Which way I should do, and why ?
Any help would be greatly appreciated.
You use UIView when you already have a view and you do not need to have a dedicated view controller to build and handle interactions within it.
From the UIView help page:
UIView object claims a rectangular region of its enclosing superview (its parent in the view hierarchy) and is responsible for all drawing in that region ...
Simplified structure:
YourViewController ---(has)---> UIView
You use UIContainerView when you need to embed another view controller in the one that you already have. The embedded view controller is in charge of returning a view for the region that the UIViewContainer occupies. Therefore, your UIContainerView knows which view controller to use to render UIView inside the region it occupies.
From the UIContainerView help page:
Container View defines a region within a view controller's view subgraph that can include a child view controller.
Simplified structure:
YourViewController ---(has)---> SubViewController ---(has)---> UIView
That SubViewController returns a view and handles its events.
As an alternative answer, you can also consider the use case instead of the technical differences. For example: Why use a container view?
A common use for container views is to reuse (share) a view, directly in the storyboard. Previously, reusing a view required creating a separate "xib" file, and programmatically adding that view when the view controller was loaded.
The above image is from this extremely simple, easy to follow guide that walks you through how to setup a container view that is shared between 2+ view controllers.
A few other thoughts on when to use it:
A navigation bar is part of a UINavigationController, which is a container view controller. So, if you wanted to build a custom alternative, you'd probably use a container view.
A container might help anytime that you want to temporarily show a complex view on top of your current VC but can't/don't want to present another VC modally. This approach still allows you to build that temporary view in interface builder, to setup auto layout constraints for it, etc
I also found a guide explaining that there's a way to switch out different container views based on the situation, allowing your VC to have sub-sections which are very dynamic, yet without having to build those sub-sections programmatically. A picture, from that guide, exhibiting what I'm referring to:
Hopefully this helps people who are trying to figure out when a container view applies to them. If you have other example use cases, please edit/add them or leave them in the comments!
If you see in detail these container view of UIView class type. To get the insights of why we need containerView you should see below portion
In most ways, a container view controller is just like a content view controller. It manages views and content, coordinates with other objects in your app, and responds to events in the responder chain. Before designing a container controller, you should already be familiar with designing content view controllers. The design questions in “Creating Custom Content View Controllers” also apply when creating containers.
for more detail about container view goto link
But before you begin you should have an understanding of
and also you can check this tutorial for how to use container view.
Thus you can go for both the approaches.
Hope this will help you. happy coding :)

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