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.
Related
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).
I have finished iPhone version of my app and want my app to support iPads as well. I used a tabbar controller for iphone.. I could use the same for iPad, however, I would have too much free space on iPad if I use a Tabbar. so I have decided to use Split View Controller. Left part(table view) should be visible all the time even if it's not in landscape mode. And every time a cell is clicked, the corresponding view should be loaded to the right hand side.. By the way I am using storyboards.. Seems like it makes everything more difficult. Are there some examples of it? Thanks..
I have faced a similar situation recently. Basically you can use the split view project template to generate the basic code. After that, I created a DetailedViewControllerContainer interface and used it as the view controller for the right side view of the split view, replacing the generated DetailViewController.
After that I created several view controllers, each of them corresponds to a selection in the left side view(master view controller). And add these view controllers as the child view controllers for the DetailedViewControllerContainer.
The catch is that you will need to use code to load the child view controllers. The benefit is that the child view controllers do not need to be modified from the iPhone version. The DetailedViewControllerContainer remains the only SplitView delegate.
Take a look at the sample code I wrote on github:
https://github.com/raoying/SplitView-Sample
Till now, I've been using controller or controllers like UITabbarController, or UINavigation controller to manage the UiviewController hierarchy. however, in the current project, i've been presented with a situation where my friends are recommending that I do away with controller of controllers and instead instantiate sub-UIViewControllers within the RootViewController and keep them as attributes. My question is whether this is a good practice MVC wise and memory management wise? (this is for iOS 5.0 with ARC)
The project requires a screen to have a header, main content area, and footer. the header and footer present dynamic content, but are the same for all screens but in the main content area, different screens can be presented either transitioning in from the right (like navigation controller would do it) or would appear modally.
I've tried to stick to MVC with one ViewController managing one view hierarchy... the above seems to go against it, but it seems to help in the situation.. so is this the right way to go or am I missing some other more optimal way?? Pls help
Thanks for your help in advance..
Why even have to have references to the view controllers themselves if you can just keep a reference to the view they manage? Sure it breaks MVC, but I love being able to divide reusable interface classes and then simply add their view's as subviews. It works, so long as you are smart about the whole thing. Is there anything specific about this pattern you'd like help with?
Go through this blog..Hope it helps you,
http://borkwarellc.wordpress.com/2010/07/22/qff-kitchen-mvc-part-1/
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.)
I'm trying to create an iOS 5 application with a SplitView Controller that uses multiple detailviews. Here's the rub. I'm trying to do it using Storyboards. I've found a number of tutorials explaining how to do it in previous versions of Xcode, but none addressing Storyboards.
The one exception creates a tab bar controller in the master view, which is not something I want to use. I tried removing the tab bar and modifying the code but was unsuccessful.
I did figure out that I could attach a replace Segue to a static cell in the master view. It allows me to specify the type as a detail split, which accomplishes most of what I'm trying to do. It loads the new detail controller.
However, the button that shows the master popover disappears during he transition. I believe I can probably prevent that from happening using this method:
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
Unfortunately, I'm not sure exactly what code to place there to prevent the button from disappearing. Do I need each detail controller as a delegate to the master somehow?
Has anyone gotten multiple detail views to work using storyboards and if so can you point me in the direction of a good tutorial? Thank you so much for the help!
I faced a similar situation and checked the link to the raywenderlich.com. However I found managing the splitview delegate kind of too complicated, and it makes reuse between iPhone and iPad difficult. My solution is to create a DetailedContainerViewController as the right side view controller. And add the view controllers to be displayed on the right side as the child view controllers of the container controller. In this way only the DetailedContainerViewController needs to implement the SplitView delegate. So there is no need to worry about the delegate.
Take a look at the sample code I wrote on github:
https://github.com/raoying/SplitView-Sample