I am navigating 6 navigations down..and from sixth navigation page i want to transfer something(some string value) to First PAge .If i continue the navigation the navigation controller maintains the stack and while going back i have to come across all previous navigated views. If i am popping from Sixth navigation view to First it is not carrying any value.How to do this..any another logic to carry string or data ?or to clear the navigation controller Stack ?
If you wish to send information you might want to go through the app delegate or create a custom delegate that you wire up in Interface Builder.
I would create a new method in the AppDelegate (ex. -(void)didChangeSixthPageString), then call it from SixthPageViewController. In the AppDelegate you probably have a reference to the the first view controller, so you can pass it the string.
Related
I am using this to pin the location.
I have one screen where I am taking inputs as Name, Address, Location.
For Location I am filling data from map with lang and lat.
For that what I am doing is if I click on main screen, I go to another screen (Map Screen) as Push. I pin there location and click Done.
- (IBAction)doneAction:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
On clicking done button, I am coming back to main screen where I have written some data. Now what I want to do is when I click Done on Map Screen, I want to write lang and lat in main view controller location label (I know how to read lang and lat.. I just want to write that text in main view controller)
Any idea how to get this done?
Use delegation to pass that information from the Map view controller to the main one.
Have a look to this answer, the part "Passing Data Back". You could also use a block in your map view controller as well.
Google for the delegate pattern.
Use the calling view controller as some locationReceiverDelegateor so. Then call your delegate from the doneAction Method and pass the loction to a method, that the delegate provides.
Do it properly by defining a protocol that declares all the delegat methods (even if there is just one) and in the setXYdelegate check for the conformity top the protcol using the conformsToProtocol method of NSObject.
I am using a tabbar, each tab having a navigation controller, and this in turn having a stack of views. Each view is having its own view controller but this is not important now.
Lets have a tab 1 with a navigation controller 1 with views A, B, C.
The nature of the application dictates however that the view B is the primary one.
So what I want is that by default (after first or after relaunch of the app), when I tap the tab 1, I will see the B view together with the back button to A view.
How can I achieve this?
You can set up a delegate for your tab bar controller and implement tabBarController:didSelectViewController: to detect when someone taps a tab. If you detect that A is about to be selected and you want B to be displayed instead, you can tell A's controller to use its navigation controller to push B's controller.
Try initializing and pushing view B (without animation) onto the navigation stack in viewDidLoad of view A.
You could use the setViewControllers:animated: of UINavigationController.
Depending on your exact needs you could set this in your app delegate applicationWillEnterForeground: or applicationDidBecomeActive: methods.
I recall there being an Apple sample app that does exactly this. The general idea is to save the last visible view controller (or just hard code the one you want) and then push it to the visible state using something like so:
[myNavigationController pushViewController:viewControllerToBeVisible animate:NO];
You'd want to show the apps tabBarController:didSelectViewController:, and handle the different cases based on which viewController was selected.
For my new app I'm planning to use UINavigationController to push/pop other controllers.
Here is the scenario.
Application is running. Via navigation controller I push first controller on the stack. The user make some selections and touch a button. Then navigation controller push the second controller and so on while the user reach the last controller which is sixth. Controllers from first until fifth will never be used again in the app.
Is this the correct approach (using navigation controller) for such kind of app ?
I am not entirely sure what you mean, but I guess you need to walk the user through step 1 to 5, then when they done at 6, they cannot go back. Is that correct?
I did something similar. What I did was pop up view 1-6 modally(and navigate from 1 to 6) to interrupt from the current flow, and once the user's done, the value got passed back to the view where you populate the modal view from(delegation) and then you do whatever next.
Not sure if i answered your question. Hope it helps.
If once they reach the 6th viewController they will never go back to the other viewControllers you can always pop to the rootViewController and then push the 6th viewController on. That way those other viewControllers are not in the navigationController stack.
It sounds like you have a flow of 5 linked screens, and then the rest of your app.
If so, yes, UINavigationController would work fine here. You would push those 5 screens, and when its done you would destroy the navigation controller and replace it with some view for the rest of your app.
So the UINavigationController would control one part of your app, but not your entire app.
My UINavigationController's navigation bar is kind of static. This means, there is no back button, because going back in the stack is done via the first entry of the UITableView the controller holds. The title also always shows the name of the root item.
To achieve this I have added my own custom view to UINavigationController.NavigationItem.titleView
It looks a bit odd if a new controller is pushed in: the old navigation item vanishes, just to get replaced by one looking exactly the same.
Is there a way to prevent this behavior? I want the animation for the content of the controller, so pushing the new controller without animation is not an option.
Add your own UINavigationBar and implement your own delegate and custom animations for the content views.
It sounds like you'll only need one UINavigationItem, so that makes this model easy to manage.
I have a little problem with the OnNavigatedTo method in the INavigationAware interface.
When I show my view with RegionManager.RequestNavigate(myRegionName, myViewName),
the OnNavigationTo method is called.
But when I use RegionManager.RegisterViewWithRegion(myRegionName, typeof(myView))
I can not get this scenario, and after that, I call
RegionManager.RequestNavigate(myRegionName, myViewName2) to my second view i am having a call to OnNavigatedFrom method of my first view.
My question is:
Why OnNavigatedTo method does not called and how i can get notice about view is shown when i use RegisterViewWithRegion?
Registering using the region manager will show the first view that was registered with it. It will never call OnNavigatedTo. Basically, to get it to do what you want to do, you'll need to "navigate" to your first View without OnNavigatedFrom to be called. To do this:
// Register all your views into the region
// The first View that is registered is automatically activated
regionManager.Regions["myRegionName"].Add(myView);
regionManager.Regions["myRegionName"].Add(myView2);
// Deactivate the View so it doesn't show in the UI
regionManager.Regions["myRegionName"].Deactivate(regionManager.Regions["myRegionName"].ActiveViews.First());
// Now navigate to your first screen
regionManager.RequestNavigate("myRegionName", "myView");
OnNavigatedTo should be called once, and OnNavigatedFrom should only be called after you request navigation to another View.
To allow view navigation you have to register it as an object, try something like that:
_container.RegisterType<Object, MainView>("MainView", new TransientLifetimeManager());
_regionManager.RegisterViewWithRegion("MainRegion", () => _container.Resolve<MainView>());
the first line allow you view navigation while the second will automaticly resolve the view as the region is created