If I have a UIViewController in a UIScrollView how can I programmatically make the UIScrollview zoomToRect? - iphone

I have a scrollview that has a page control. The scrollview contains 3 views. Each view contains a view controller. In one of my view controllers I press a button and I want the scrollview to scroll to a specific location. But Im not sure how to accomplish that since the button is not in the UIScrollview but in one of the view controllers. Could anyone point me in the right direction with this? I have spent a lot of time trying to follow the view hierarchy to see if I can send a message to the scrollview for it to scroll. Any help is appreciated.

You can:
Add a delegate in your 3 inner View
Controllers that points to the View
Controller that holds your Scroll
View.
Create a method in the View
Controller that holds the Scroll
View that will call [scrollView
zoomToRect:] when called.
Access it from your 3 inner View
Controllers using the delegate.
If you need more information about delegation. check what is Delegate in iPhone?.

Related

iOS 5 Partial Transitioning View Controllers

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.

UIViewController inside UIView not getting rotation delegation

I have a UIViewController's view inside my UIScrollView subclass. The problem is my UIViewController is not getting the willRotate delegate called when I rotate the device. This is probably because UIView does not have a rotation delegate implemented in it. What is the best way to solve this?
Basically the structure is I have a MainViewController in which it has a UIScrollView. Inside this UIScrollView I have a subviews, which is the view of a bunch of UIViewControllers. The issue now is, it's not getting rotation calls when I rotate. One way to deal with this is to delegate from the MainViewController to those respective UIViewController. Is there a better/elegant way to solve this?
I am adding it as a subview from my UIScrollView not my MainViewController and you can't do UIViewControllers containment from a UIView. Correct me if I am wrong
I think you're going against the MVC pattern. You can't have a controller inside a view; instead you should have a controller that mediates the communictaion between the view and the user's input. In your case you could set the scrollview as self.view of the MainViewController, and then add the viewcontrollers views as subviews.
Watch the video that I posted in my comment: https://developer.apple.com/videos/wwdc/2011/?id=102
Here is a short summary of view controller containment, which is the design you are looking for, not combining all your logic into one view controller or using delegation for something that is built into the SDK.
A view controller has a view and provides logic for that view and most likely some of it's subviews.
You might have a complex view hierarchy and complex logic for specific views in that hierarchy that warrant the view to have it's own view controller controlling it and it's subviews.
Say you have a MainViewController and it's view is a UIScrollView (or subclass). Inside that scrollview, you might have an assortment of complex views that warrant their own controller, so you have a class, SubViewController that has the subview of the scrollview as it's view.
SubViewController needs to have rotation and appearance method callbacks working correctly in order to implement your logic for the the subview and handle layout changes.
[mainViewControllerInstance addChildViewController:subViewControllerInstance];
But, wait. The subview is still not in the view hierarchy.
[mainViewControllerInstance.view addSubView:subViewControllerInstance.view];
You have successfully created a valid view controller hierarchy of two view controllers and set up the associated view hierarchy of their views.
You will now have the appropriate callbacks functioning, as MainViewController will forward them to SubViewController.
EDIT:
See the documentation for an over view of view controller containment: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

positioning UIViewController containment children

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!

Appear TableView when a view is touched

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.

How do I push a new controller via UIButton, nested in a UIScrollView?

I have my views that are part of a tabBar. Each view has a navigationController.
In one of my views I have an embeded xib component. This is a scrolling view
with UIButtons inside it.
I want to slide in another view, inside the navigationController when a person taps the button. I can get the taps, etc.
BUT, I can't figure out how to find the controlling navigationController of that page to push the new view into. Nothing seems to work that I have tried.
IS this possible?
Thanks
You need to pass a reference to the navigation controller "down" your view hierarchy. Or pass another object that has a reference to the navigation controller "down". Or get the app delegate if it has a reference to the navigation controller.