Using NIBs with a UIPageViewController - ipad

I am trying to use a UIPageViewController to create a book app. Each page currently has its own viewcontroller and Nib and has its own set of unique features. I am not using Storyboarding since there are over 40 pages to the book app.
I have had a hard time finding out how to use NIBS (with their view controllers) with UIPageViewController. The UIPageViewController will switch to the desired viewcontroller/NIB, but will then not respond to any of the UIPageViewController gestures.
Is there an example of using the UIPageViewController with NIBs that might help?
Any thoughts? Thanks for your help!

This was a very nice tutorial: http://www.techotopia.com/index.php/Implementing_a_Page_based_iOS_5_iPhone_Application_using_UIPageViewController
As an added bonus, it deals with Xcode 4.2 details, like de-selecting storyboard on project creation.

My guess is that you forgot to retain your UIPageViewController object. That happened to me the very first time too! The result is that the initial page(s) display but you don't get gestures, because the page view controller no longer exists. Stuff the page view controller into an instance variable with a strong/retain policy right after you obtain it.

Yes. You can use nibs with UIPageViewController. Without storyboarding. See this:
http://www.ioslearner.com/implementing-uipageviewcontroller-programatically-without-storyboarding/

Related

Best approach for 1 screen contains 2 view controller

I want to learn parent - child concepts in iOS. I found a some app in app store and I liked the their design. They have 3 button in same view controller when the user taps a button below view changes and calls their view controllers. Like a TabBar.
I tried to create 3 xib files. When the user taps the buttons they are awaking from nib and I added them to my containerView subview. It works. But I couldn't send a data between them because there is no prepare for segue method to so i couldn't prepared them.
I tried to create 3 viewController in Storyboard and I use them with the Storyboard ID. It works. But still can't transfer data between them.
I didn't understand what is the best approach for solve this problem ? I researched on the web about Custom Segues and Parent - Child concepts but I couldn't find anything.
What is the best approach for make a container like in the image ?
Thank you.
I am not sure if there is something like a best approach, at least in general term. It really depends on your specific demands and other logic of your app.
Both creating XIB files and creating ViewControllers in Storyboard together with their ID is ok. Here it is more about your preferred way. I would say that today you will probably see more using Storyboard than XIB files.
In terms of data transition. There are several ways, if it is not some very heavy logic then delegates can do it pretty well and easy.

Is it possible to have multiple UIViews inside a UIPageViewController

I am trying to set up a UIPageViewController that swipes through three very different views. I need to have a UICollectionView, a UITableView, then another UICollectionView with a different format. Can anyone clarify, whether this is possible or not? I have been searching for the last couple days and have not found a definitive answer. I am not asking for someone to solve this for me, I simply want to know if I should give up and just go with a different approach.
Yes, it is possible.
From the UIPageViewController Class Reference:
A page view controller lets the user navigate between pages of content,
where each page is managed by its own view controller object.
You need to have a viewController for each page. I recommend you read here: https://developer.apple.com/library/ios/documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html
You certainly can. The UIPageViewController is made to display different view controllers.
Try it for yourself, it's not that hard. You'll need to implement a UIPageViewControllerDataSource to return your different UIViewControllers, but that's about it.
Yes, you can have different views inside a UIPageViewController. That is the first line in Apple documentation of UIPageViewController
https://developer.apple.com/library/ios/documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html
A page view controller lets the user navigate between pages of content,
where each page is managed by its own view controller object.
Below is method is used to set the view controllers to be displayed.
setViewControllers:direction:animated:completion:
For tutorials/sample-code, you can go through below:
https://developer.apple.com/library/ios/samplecode/MyImagePicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010135
http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
Go through these links and then start coding your requirements. You will be good to go then.

Good way in iOS to have a view outside a UITabViewController

I'm just getting back into iOS development after a year or so away and am looking for a way to have a single view above or below a UITabViewController view. The idea is to have one ad view that is used throughout the app instead of one on each tab. The constant reinitializing of the ad view seems like it would be a lot of overhead so having one persist throughout would seem to be more effective.
I've searched for this but not found much of anything so even a useful link would be appreciated.
Thanks in advance,
Jason
I see several approaches here:
Since you are setting up your view hierarchy in your application's delegate, I'd suggest creating a separate UIViewController and managing it from your app delegate. That way you can show/hide it in the main UIWindow, without having to do much work.
You can subclass UITabBarController and show the ad in the visible view controller. This is more work, but your app architecture is arguably cleaner, because your app delegate doesn't get cluttered with ad-related code.
Another option is to look into a UIViewController category, where you can manage add related code. Not necessarily the cleanest, but it keeps the ads out of both your app delegate, and your tab bar controller. (You'd add the ad view as a category property via runtime level calls and associate objects, but that gets messy.)
I'd probably go with the first approach if it were me, but I could argue for either of the other two approaches, since an ad view doesn't really necessitate it's own view controller.
How about create a parent view controller and each view controller inherits from that parent view controller? Parent view controller has a ad view or table view, so every child view controller will has those two view as well.
Okay, after spending some time trying to create and manage a customer view controller for this I stumbled on the Container View Controller capability Apple added in iOS 5. I have no need to support iOS 4 or earlier so this works good for me. There's a good description of it here (unfortunately the author never wrote part 2 with a tutorial):
Container View Controller description
And a decent tutorial is available here:
Container View Controller tutorial
Between the two of these I was able to create a good setup with an AdViewController and BodyViewController (TabBarController) contained in a Container View Controller. This gives me all the capabilities I need (at least so far).

UIPageViewController with multiple XIBs

I am building a book app using uipageviewcontroller for the new Ipad. Each page is intractable, for example there are sound files assigned to each page, by pressing a button it can be played.
My question is
I am using 20 xibs for the book, is it OK to use this much of xibs? or do I have to reuse the xibs?
If contents on each page are repeating then you definitely should reuse the same class or XIB connected to controller.
Even if you use different XIBs for each page then it should not be any issue to UIPageViewController but you have to make sure that when that page is dismissed then you are deallocating all the outlets connected to XIB files and other resources used in that page and you are not retaining that page object anywhere.
I hope that will make understand it properly.

iPad master detail app - change detail view controller's content

I started to explore the UISplitViewController class with a new master detail project in XCode, and I would like to replace the detail view's content with another UIViewControllers. I wrote it in this way (self is the detail viewcontroller and controller is the uiviewcontroller which I want to replace the first one with):
self.view = controller.view;
My question is: is it a proper way, will Apple accept it? If it is not, how could I do it better?
I am also building an iPad app with Master - Detail View Controllers in a UIIntelligentSplitViewController. As UISplitViewController doesn't support well while changing to different orientations, using UIIntelligentSplitViewController solves the issue with orientation change. See more here.
I have read on one of apple documentation and also a in best practices that we should use Only one MasterView and DetailView Controllers in entire app, and write code in such a way that all data are loaded in these two views according to the object selected.
But loading all data in same detail view might be a lot of code. So, I am also in search for answer for efficiently writing code to load in same detail view controller. However currently I am implementing only two views to show net data.
If there is any other efficient way to accomplish it, please do mention. Thanks.
You could replace the detail view controller where it is setup in your app delegate "didFinishLaunchingWithOptionsMethod". Your method would probably also work but is creating unnecessary overhead. The auto generated code they provide default's to a navigation controller on the left and a view controller on the right but you can change that to whatever you need. I have a project where I have two navigation controllers.

Resources