iOS PageViewController with different page layouts using storyboard - ios

I am trying to use the PageViewController with different layouts but I dont know how to accomplish that. Currently Im using the page-based application provided as a template for new projects in XCode 5 for iOS. This application uses the same view controller for all pages, and I want different pages. Is this even possible? And how can I add a different view while using this template and storyboard. I couldnt find any tutorials that uses storyboard and adding different pages.
I have also tried UIScrollView with paging enable. But those tutorials I found required to turn off auto layout in settings, such as this one:
http://www.iosdevnotes.com/2011/03/uiscrollview-paging/. And that is not the correct way of doing it.
Since I havent found any examples, I start to wonder if this is even possible to do in a simple way?

I don't think this is possible using storyboards in the straightforward way you want, but it can be achieved with relative ease. You can create all your different view controllers in the storyboard (these will serve as pages) and give them identifiers. Now in code, have the view controller that displays the page view controller be its data source.
Now, in – pageViewController:viewControllerBeforeViewController: and – pageViewController:viewControllerAfterViewController:, implement logic that decides which view controller to load, and use the storyboard's – instantiateViewControllerWithIdentifier: to return an appropriate view controller.

Related

Nesting view controllers inside a storyboard

I'm learning how to use storyboards for iOS development and I can't seem to figure out how to manage multiple views on the same screen.
I want to be able to control multiple elements on the same screen, for example a UITableView with an UIImageView next to it.
This means I need 3 UIViewControllers, 1 for the UITableView, 1 for the UIImageView, and one for the main view. But as far as I can tell storyboards only allow for 1 controller per view hierarchy screen. Can anyone tell me what I'm missing?
View Controller Containment is the way to go. Have a look at Apple's documentation about it:
Creating Custom Container View Controllers
Container view controllers are a critical part of iOS app design. They
allow you to decompose your app into smaller and simpler parts, each
controlled by a view controller dedicated to that task. Containers
allow these view controllers to work together to present a seamless
interface.
You can use it in storyboards as well by using a container view.
Useful tutorial: Storyboards With Custom Container View Controllers

Using single storyboard views for static table view in iOS5+ instead of using storyboards for the entire app?

Recently I was searching for an useful approach for static table views without using storyboards for my entire app. I found this answer:
Static table view cells are only available when using storyboards. However, if you aren't using storyboards for your entire UI you can still use them for individual screens instead of a collection of strings.
To do this you can create a UIStoryboard file with a single view controller on it that has it's File's Owner set to your custom view controller subclass. Set the VC's identifier to some value. When you want to display this, get the storyboard and then instantiate your view controller subclass by creating the VC from your storyboard.
Is it a good approach? Or is it better to implement it the iOS4 way?
What should be preferred in case of performance and maintainable code base?
Thanks
Maintaining code base is pretty easy in Storyboard for static pages.

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.

Using a View Controller managing two other View Controllers

I have a offlineMapVC and a onlineMapVC for my application to support both online maps (using MapKit and Google Maps) and offline maps (using Route-Me).
I made my own mapVC to manage the switching of these mapVCs and be able to use the view controller as one separate view controller. Well I've done this by making the offlineMapVC and the onlineMapVC instance variables of the new mapVC witch I now use all over my application.
First off all things seem to work but. However while using this approach for a longer time I ran into some problems due my using of View Controllers in a hierarchy. I read this is the wrong way to go. What is the right way to manage the switching between two view controllers? My question seems fairly simple but I couldn't find a decent solution.
I put view controllers in view controllers, myself, and I have seen much better programmers than me doing the same thing. (See Rob Napier "iOS 5 Programming - Pushing the Limits". He mentions it frequently.) As long as you don't have more than one view controller directly controlling the same views and subviews, you should be okay with it.
Since Jonah Williams wrote that article, I think iOS 5 formalized the use of view controller hierarchy with custom content view controllers. You might consider your mapVC to be a custom content view controller and implement onlineMapVC and offlineMapVC as child view controllers.
(Apple documentation links tend to change frequenctly, so Google "Custom Content View Controller" for the documentation.)
If you can give some more context to what you mean by "switching between two view controllers" that would help answer your question. Generally, I have more than one view controller active at the same time. I don't switch between them. (I use navigation and tab bar controllers in the same applicaiton, but I assume you are aware of how those work and you're asking a different question. It's just not clear what the detials are in your case.)

multiple "content views" on the same xib

I have a ViewController (with navigation) that needs to show 7 different content layouts. I want to keep the same background and nav, the only thing that needs to change is the central UIView.
If I have 7 different UIViews on the same xib/storyboard, can I hide the ones I'm not using or will that ding performance?
Using segues won't work either because they make a mess out of my custom navigation and animations.
Is there a better way to accomplish what I am trying to do? Thanks for suggestions
solution
My design is too custom for using view controller containment so I decided to mimic the idea with a custom UIViewController and two UIViews. It's not too bad and it works rather quickly.
You should look into using view controller containment, then you can load your views from separate nib files and still provide your custom navigation and animations from your container view controller.
Note: This is only really supported from iOS 5.
Generally, it's a good idea to unload views that aren't visible, however, if your views aren't using too much memory (and/or cpu time) hiding them when they're not in use should work fine.
View controller containment is probably what you should be doing if each view has its own unique functionality (i.e. view 1 is a map, view 2 shows some about text, view 3 is an image gallery). UITabBar might be useful, but it depends on your app.
The performance hit would depend on your views' contents. If you haven't done so already, invest some time into learning how to use Instruments (apple's diagnostic tool). Watching the video titled "Optimizing App Performance with Instruments" in the developer resources would be a good start.
My design is too custom for using view controller containment so I decided to mimic the idea with a custom UIViewController and two UIViews. It's not too bad and it works rather quickly.

Resources