I am having trouble to find out the best way of transitioning only a part of view controller.
This is what I have:
In my first view controller, I have a UIView that acts like a header where I provide some ImageViews and Labels, bellow it I have a table view.
When user clicks a cell from the table, another view controller is pushed and it contains the same UIView header as before and bellow it some detailed information about the cell item selected.
This is what I want:
Since both view controllers have the same UIView header, I would like it to be fixed and only change the bottom contents (table view or detailed informations). I expect a transitioning effect that only move the contents on the bottom.
I appreciate any guidance.
A View controller controls views, so it isn't a case of transitioning view controllers, you can do this by transitioning views.
You can have multiple views. that occupy portions of the window.
In your case you could keep the top view (the one that you call the header) and when you need to change a part of the view your controller just needs to create a new view to display and then you can animate it into it's new position on top of the old view.
UIView animations let you accomplish this. For example, you could use transitionFromView:toView:duration:options:completion: to animate from your table view to the detail view.
It is possible to have a different view controller for this detail view if you want. All you need to do is create the view controller with the information that is needed to configure its view, and then pass this view as the toView to the above method, and then when you are done with the view, you can use the same method to transition back to the original tableview.
Related
I want to put two UIViewController in one screen simultaneously in UIKit. However, I couldn't find the solution.
Like this:
I want to display both UINavigationController and Admob Banner in one screen and independently. The one doesn't affect the other.
Could you tell me how to do this?
You want to use view controller containement. The easiest way to do this is as follows.
Open your storyboard.
Add a view controller. Let's call it "Parent". Give it a unique identifier.
Tap the "+" to add a new component to your parent view controller. Search on "Container" and drag 2 container views onto your parent view controller. Those container views will contain the content view of your 2 view controllers. Set up the constraints on those container views so they are laid out top and bottom as you show in your picture.
Next add view controllers for view controller 1 and view controller 2 to your storyboard. (you can also add links to view controllers from other storyboards, but I'll ignore that.) Lets call those Child1 and Child2.
Control-drag from each container in Parent onto the child view controller you want to appear in that container. When prompted, select that you want to create an "embed segue".
An embed segue tells your app that it should load the child view controllers when Parent is loaded, and make their content views subviews of the container views.
In Parent, the PrepareForSegue() method will fire as each child view controller has been initialized and its view is getting ready to be loaded. At that point you can pass information to the child view controllers, set up delegate links, etc. (Note that you can't, and shouldn't, manipulate the child view controller's view hierarchies directly. Instead, pass data to the child view controllers using proprerties or methods of those view controllers, and have the children's viewDidLoad methods install that data into the views as needed.
I'm trying to pop up a view controller from the bottom of the screen but I want a view from its parent view controller to show on top of it so that it slides up from underneath this view. There's no interactivity with this extra view on top of everything. Is there a reasonably simple way to do this?
There are various ways to achieve this:
You can create a xib and add over the view controller.
You also create a programmatically view and add over the VC.
You also can drag view over the VC in storyboard and initially hide the view.
Show with the animation.
I was reading the documentation:
You need to decide how many children can be displayed by your view
controller at once, when those children are displayed, and where
they appear in your view controller’s view hierarchy.
But in which method should I position the view controller children's view? Say I have two UIViewController in the container and I want one next to the other.. how do I do this?
In one of my articles I demonstrated how to create a simple dashboard app using UIViewController Containment.
http://www.highoncoding.com/Articles/848_Creating_iPad_Dashboard_Using_UIViewController_Containment.aspx
Each of the child view controllers has a view property. You can set the frame of those views when you add them to your own view.
It depends on the context of the situation that you may have. If you need to display all of the children when displaying the view for the first time, then add the view controllers and views in viewDidLoad ( if using a xib or nib) or in loadView ( if done programatically). If you need to show the child view controllers on demand, like after the touch of button, then you can add the child view controller and associated view in a separate method.
You will need to layout the views of the child view controllers as you would layout any other subviews. Remember view controller containment is just another ways of allowing you to modularize your code.
Check out this link which helps explain how to add the child view controllers: Animate change of view controllers without using navigation controller stack, subviews or modal controllers?
Here is a simple sample project that shows how to add child view controllers:https://github.com/toolmanGitHub/stackedViewControllers
Good Luck!
I have an application that is divided into 4 quadrants, each quadrant is a view. Each view I have to fill it with a graph, for which I am using Core-Plot. I want when you touch a view appear a tableviewcontroller, but I cant do it. I have researched, but all I get is the ViewController in full view.
The idea is like this:
https://skydrive.live.com/redir.aspx?cid=a9f400f6a1d61745&resid=A9F400F6A1D61745!414&parid=root
I can't put the image because is my first post.
How could implement?
This is not the only TableViewController, because choosing an option leads me to another table view and so on to the data. There are 4 levels.
Thanks
I would create four navigation controller with the view controllers which manages the core plot view as root view controller. Than add the view property of the navigation controller to the main view ([mainView addSubview: [navigationController1 view]).
I don't know whether this works but I would try it this way.
I'm a bit confused as to implementing custom view controllers. I have a view that I want to have slide down from the top of the window. The view has three buttons on it. When the button for the view to drop is tapped the view drops. And when tapped again the view slides up/goes away. I have the drop down view saved as a nib file. Would this be the best method for implementation? Or should I have the view in the main view's nib?
And could I get some direction on how I should set it up?
The usual pattern has each of the view's stored in their own XIB file and associated with their own view controller objects. You then alloc/init the new view controller and point it to its XIB and present it modally. Once its presented, its VC responds to its actions and interacts with the model and updates its own views. You can then dismiss that view controller and its views to revert back to the parent view controller.
I have noticed a pattern mentioned in SO where people alloc/init a child VC and then within their present VC they addSubview the newVC.view, but that just seems pretty unusual to me.
If you just have a subview that is being animated down to partially cover the screen, perhaps it doesn't warrant its own VC since, as I think I'm understating your usage, its actions would map to your current VC. In that case, I would either create its contents programmatically or just as another view in the XIB for your first VC and animate that down when needed.