Why need to add subview again after add child view controller? - objective-c

Since I hava a parent view controller and a child one,
parent view controller is something like a container controller that apple doc said,
then do
[parentVC addChildViewController:childVC];
childVC.view.frame = SOMEFRAME;
but now childVC has not been seen in the screen;
must I add code below?
[parentVC.view addSubview:childVC.view];//is a must? any code can replace?
--
At my sight,container is container,when I had added a childVC in,it's view should add itself,or some method can do that?.
UIWindow has a property of "rootViewController",when set it,the new view will be added automatically,I think this is what I want.
I need some advices.thanks.

It's a simple matter of control. Often you want to have a child view controller, but it's view is a subview of one of your subviews, not simply a subview of the "top level" view property of the container view controller.
Essentially, the framework chooses to let you decide, and does not enforce that a contained view controller's view must be a first-generation decedent of it's parent view controller. It's completely up to you; the hierarchy of ViewControllers and Views do not need to have perfect generational parity.

Related

A view switching framework for "true" MVC on iOS

I don't like the UINavigationController because the tree/drill-down navigation style does not work in all situations. What I'm looking for is a sort of UISwitchController where a view controller can tell the UISwitchController what the next view is and the data to pass to it. Then the current view closes itself and the UISwitchController would handle opening the next view and passing in the data from the previous view. The UISwitchController could remember the name/type of the last view opened so the current view could tell who opened it (also allows the UISwitchController to handle a Back request by the current view without the current view specifying the name of the view that opened it). A view could also flag the UISwitchController to keep it in memory and not to release it after it closes so the view controller is essential reused for each call to that view. Is there such an framework?
So basically you are talking of a UIViewController that holds several UIView(Controller)s and handles the presentation.
In iOS < 5 I would just use a UIViewController, that adds views to another view, that is displayed.
in iOS 5+ you should familiarize yourself with UIViewController Containment, that is actually a pattern of how to use UIViewControllers with other child view controllers.
form the UIViewController doc
Implementing a Container View Controller
In iOS 5.0 and later, custom UIViewController subclasses can also act
as container view controllers. A container view controller manages the
presentation of content of other view controllers it owns, also known
as its child view controllers. A child’s view can be presented as-is
or in conjunction with views owned by the container view controller.
Your container view controller subclass should declare a public
interface to associate its children. The nature of these methods is up
to you and depends on the semantics of the container you are creating.
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. Your view controller
class defines what relationships, if any, are shared by the children.
By establishing a clean public interface for your container, you
ensure that children use its capabilities logically, without accessing
too many private details about how your container implements the
behavior.
Session 102 - Implementing UIViewController Containment — WWDC 2011
I haven't used it much so I don't know if it's exactly what you're looking for, but you can use TTNavigator from the three20 framework to do URL based navigation which sounds like it could be what you want.
https://github.com/facebook/three20

How to know Present view of UINavigation controller iPhoneSDK

i have one navigation controller, by using that i am pushing my view
here my problem is how to know that which view is presently appearing on my navigation controller
can any one of you give me the answer
Probably you want to look at the topViewController property of your UINavigationController (or perhaps its visibleViewController if you are using modal views). The current view would then be referenced by the view property of the returned controller.

Create a UIViewController that contain a UIViewController

I have a UIViewController that allow me to display some text into a view.
I want to add an input method without add it directly into this view controller, this input method will be a button or a UITextField.
This input method will be a lot, but it will be use one at time chosing it from setting so a I won't to have a UIViewController that control all of this.
What I want is know how it's possible to split the output view (controller) with each input view (controller)?
You can image to have a text view on the top of the screen and some other view at the bottom and I will to separate the logic of the second view from the logic of the first one
Is it clear?
Of course it is possible to have 2 UIViewControllers on screen at any time! There are a few ways to go about this:
Using One Main View: Add the second ViewController's view as a subview
Using Interface Builder: Drag in a UIViewController Object, set it's class, then hook it's View outlet to a UIView in the first ViewController.
Child View Controller: As it's name implies, the -addChildViewViewController: method will add a new ViewController as well, then add it's view as a subview.
Yes, it's possible. Just add the controller as a child controller ([UIViewController addChildController:] and its view ([controller.view addSubview:childController.view]).

Add other objects to iOS 5 storyboard after tableview

I have a simple iOS 5 storyboard that contains a tableview controller scene. However, the table UI takes up 100% of the real estate and I am unable to add any additional objects such as a title bar. Any object that I drag to the scene will try to size correctly and what-not but as soon as I let go it will not add the object. What am I doing wrong?
If all you want is a title bar, then it looks like you want to embed your table view controller in a navigation controller. You can do this by selecting your table view controller and using the Editor: Embed In: Navigation Controller menu command. Once you do this, you should have a navigation bar, and you can double click it to edit the title.
If you need arbitrary UI elements along with your table view, then I think you need to use a plain UIViewController scene instead of a UITableViewController, and manually drag a UITableView into the scene. Your view controller would not subclass UITableViewController, instead it would subclass UIViewController and implement the UITableViewControllerDelegate and UITableViewControllerDataSource protocols. Also, you would need to manually wire up the delegate and dataSource outlets by ctrl-dragging from the table view to your view controller in interface builder, and your view controller would need a custom tableView outlet that points to the UITableView and is correctly wired up in IB. Perhaps there is a simpler approach than this though, if someone has a better suggestion that would be great to hear.

Access Parent View Controller from tableViewController in popover view

I am trying to implement a popover view in a tableview controller. My intention is for the user to select an option from the table list as shown below.
Note that my popover view actually displays the data from a separate table view controller. I am creating the popover view controller via the following initialization method
self.popOverViewController = [[UIPopoverController alloc]initWithContentViewController:optionsTableViewController];
After the user selects an option for example "Hottest All Time", the control should be passed from the tableview Controller (in the popover view) back to the MAIN table view controller (parent view) so as to trigger a table reloadData method.
Query: Is there a way to return the control from the tableview controller in the popover controller back to the MAIN tableview controller?
Do I have to use a delegate method to do this?
The two approaches I've seen are roughly the standard sort of fare:
create a delegate protocol for the class type of optionsTableViewController, have the controller that creates the popover implement it and set itself as the delegate when issuing the popover
use the NSNotificationCenter (which actually fits the intended purpose of the thing if you've a one-to-many message, as may be the case if you've a popover with a setting that affects a bunch of different controllers and you don't really care which is visible when the user requests the popover)