I pretty new to Xamarin.iOS and I need some help on the navigation.
To make it short, here is how the navigation should work in my application:
My application consists of 3 screens.
Screen 1 :
This is a simple UITableViewController where I can add items to the list.
When I add an item I have a segue (show details) to screen 2.
Screen 2 & 3:
Screen 2 is embedded in a UINavigationController.
Screen 3 is the end of my wizzard to add an item.
On screen 3 when I'm done, I have a button to navigate back to Screen 1.
How do I navigate from there and remove from the stack the UINavigationController, Screen 2 & 3?
use the PopToRootViewController() method on UINavigationController
nav.PopToRootViewController(true);
From Xamarin docs: Creating an Unwind Segue
An unwind Segue can be used to navigate back through a push or modal segue - for
example by dismissing the modally presented view controller. In addition to this, you can unwind through not only one, but a series of push and modal segues and go back multiple steps in your navigation heirarchy with a single unwind action.
You just need this piece of code in the target UIViewController
[Action ("UnwindToTargetViewController:")]
public void UnwindToTargetViewController (UIStoryboardSegue segue)
{
Console.WriteLine ("We've unwinded to Target!");
}
On the OriginViewController, just link a button with the exit scene and select the method you just created!
Related
I can use navigation without segues (1) but I would like to use it (2).
Performing a segue and navigating back make my app slower ! Because it doesn't dispose destination view when I navigate back. How do you use this segues in a right way ?
/*1) This code ok! But what about segues */
if(_tabbarController==null)
_tabbarController = (UITabBarController)this.Storyboard
.InstantiateViewController ("MainTabbarController");
this.NavigationController.PushViewController (_tabbarController,true);
/*2) If I run this code I get a new instance of UITabbar */
this.PerformSegue("SegueShowDetail",this);
If you're using the Storyboard and a Navigation Controller, the navigation controller should automatically release your view and associated memory with it when it pops off the stack.
For example, if you've got a method that gets called when you push a button to go to another view, you'd have:
[self performSegueWithIdentifier:#"mySegueName" sender:self];
When you click the back button at the top left of your secondary view, this will trigger the navigation controller to dispose of the view.
This walkthrough for MT.D shows a back button on the UIDatePicker that appears when a DateElement is tapped. I'm in an iPad app, and using an MT.D DialogViewController as a subview in an overall UIView. When the date picker slides up I just get the black background with no way to dismiss the picker (no nav bar w/ back button). Same problem exists for the radio group picker. Is this because the dialog view controller is being used as a subview? Any ideas how I might get a nav bar up with a back button using the built-in picker logic?
You must use the DialogViewController as a child element of a UINavigationController to get the back button. On iPad, you can embed the UINavigationController in a UIPopoverController.
Adding the view of a controller into the view of another controller is not considered good design on iOS and won't result in the behavior you expect.
Currently in my app I have this design:
-- DialogViewController 1
-----DialogViewController 2
--------DialogViewController 3
-----------TabBarController
--------------DialogViewController4
--------------DialogViewController5
--------------DialogViewController6
--------------DialogViewController7
Problem with this is that dialog view controllers 4-7 breaks the monotouch dialog flow (so to speak), because of TabBarController in between. When I create dialog view controllers 4-7 I need to create new Root in their constructors which I don't need to for DVC 1-3.
With this approach certain things like radio groups don't work inside DVC 4-7 e.g it will display the radio group selection, but there is no navigation bar at the top.
My question is what can I do to solve this? Can I use TabBarController inside DVC somehow if that makes sense? Or how can I "hook" DVC 4-7 back to main "circuit"?
Thanks in advance.
According to the iOS HIG
A tab bar appears at the bottom edge of the screen and should be
accessible from every location in the app
which implies that it should be the root, not nested inside another controller.
How can I arrange (programatically) the back button of a UINavigationController in a different position?
For example, suppose that the back button (visible in the upper bar of a UINavigationController) has these coordinates: 67 for x and 10 for y. I would arrange the back button for these coordinates: 89 for x and 10 for y.
Do I have to override these measures in a specific method (for example viewDidLoad() method)?
Thank you. Regards.
I guess this cannot be done in a simple way as you can manipulate the navigation bar only via few properties. So there are basically two methods:
1) traverse the UI tree and search for the actual button control created by iOS for you in the navigation toolbar and change its Frame property. You can always get to the inner controls by the Subviews property, so call navigationController.Subviews and iterate through that until you find the control you would like to move, btw it could be deep in the hierarchy, depends. And with iOS update this can change, so this is a bit of a hack, but usually such technique works well.
2) do the custom way. Hide the actual navigation bar, and do the navigation yourself via custom buttons, add a UIButton to your interface, in the action for that call popViewController on the navigationController. If you're inside a view controller, you can use this.navigationController.PopViewControllerAnimated (...);
If you need nice buttons, use this PSD, works well for me http://www.teehanlax.com/blog/2010/06/14/iphone-gui-psd-v4/
Hope this helps. If so, please vote.
In my windows based applicaton, after login screen and registration page I added navigation controller for next two views. After pressing button present on second navigation window,again i want normal view controller and not navigation. But Its giving me navigation window with back button which takes me to second navigation window.
Can anyone plz tell me the solution??
You have a couple choices: you can truly eliminate the Navigation Controller entirely and replace it with another UIViewController (more complicated), or you can just push a new UIViewController that will not have a navigation bar/back button, and use that as the effective "root" view controller of your application from there on out. Without the navigation bar, your view controller will look like a "normal" view controller.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.hidden = YES;
...
}