How to know Present view of UINavigation controller iPhoneSDK - objective-c

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.

Related

How to add multiple view controller in a page controller

I want to add multiple view controller in a page controller so that view controller can scroll left and right side in page view controller.
How to do like this..?
You need to implement the UIPageViewControllerDataSource. All the documentation is found here:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPageViewControllerDataSourceProtocolRef/index.html
In the
pageViewController:viewControllerBeforeViewController:
pageViewController:viewControllerAfterViewController:
methods you return the UIViewControllers you want to show.
With the
setViewControllers:direction:animated:completion:
method from the UIPageViewController you can set the initial UIViewController.

Adding Navigation Item in UIViewController

I'm trying to add UINavigationItem to my UIViewController as mentioned this answer. However the Navigation bar is not showing in my view. I tried even adding an outlet and setting the title programmatically and also adding the NavigationItem in two different places. Still it doesn't show. This view controller is embedded in a TabBarController. WHat am I missing here?
Thanks is advance.
This view controller is embedded in a TabBarController
But is it embedded, first and foremost, in a UINavigationController? If not, there will be no navigation bar that automatically appears and that automatically uses your view controller's navigation item.
If you don't want to use a UINavigationController (because you have no navigation to do), then you can add a navigation bar manually. But in that case your view controller's navigation item will not be used automatically to populate the navigation bar; you must populate it manually.
Typically, people do use a UINavigationController, even if there is no navigation to do, just to get this automatic behavior - to show the navigation bar and to populate it automatically.
[NOTE: The fact that you have told Interface Builder to show a navigation bar for this view controller, as if it were in a navigation controller, is irrelevant; that won't cause you to get any navigation bar when the app runs.]

Why need to add subview again after add child view controller?

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.

Interplay between UINavigationController’s addChildViewController and topViewController

I have something like a modal view controller that I need to display above my other view controllers. I’m not using the regular modal controller feature (presentViewController: and friends), since I need better control over the process. Instead I am using the view controller containment feature (the addChildViewController: method group).
The containment feature makes the code fairly straightforward. When I need to present the “modal” view controller, I add it as a child to the view controller hierarchy and everything works as expected. One small catch is that the regular view controllers are wrapped in a navigation controller. Therefore I have to add the modal controller as a child of the navigation controller, otherwise it would be covered by the navigation bar and toolbar.
Now the problem is that calling addChildViewController: on a navigation controller also sets the new controller as the topViewController, as if the controller was pushed using the regular pushViewController: method. This means that while the modal controller is displayed, the regular controller underneath it does not receive the appearance and rotation callbacks.
This feels like a bug, or am I missing something?
I had the same problem. I resolved this by writing my own custom view controller, containing a UINavigationController (added via addChildViewController:) and then exposing the UINavigationController as a readonly property. Then you can add your modal view controller as a child of your new custom view controller instead of as a child of the UINavigationController
I missed this sentence in the documentation for addChildViewController:
This method is only intended to be called by an implementation of a
custom container view controller.
So I guess it’s my fault and this scenario is simply not supported. Which sucks, because it’s very convenient to design whatever modal things as regular view controllers and connect them to the hierarchy like proper first-class citizens. I would probably have to rewrite the navigation controller on my own to have built-in support for this.

What methods are called when returning to UINavigationController's root view?

What methods are called when returning to a previous view, or the root view, of a UINavigationController?
Also, when the user taps the back button to return to the previous view, is everything in the view that's disappearing released, and its values unretrievable from the parent view?
viewWillDisappear:animated: will be called on a view controller before it is popped from the navigation stack.
This is the place to do anything that you need to do when the user goes "back" in the navigation controller. You can access any other controllers in the navigation stack via self.navigationController.viewControllers which is an array of all the view controllers currently in the stack, with the root view controller at index 0.
You can use the viewWillAppear, viewDidAppear, viewWillDisappear and viewDidDisappear in your view controllers. This works independently of UINavigationController.
UINavigationController also has two delegate method. Maybe they would help you:
navigationController:willShowViewController:animated:
navigationController:didShowViewController:animated: