Xamarin Forms to native & back query - ios

Following is the navigation stack I have in my app
page 1 (forms)-> Page 2(Native IOS with Page renderer) -> Another IOS native view via UINavigationController (to select an image from photo galary & process it)-> Page 3 (forms)
Here is what I am trying to do:
Page 1 in forms: Click on a button
Page 2 in IOS using page renderer
Code:
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
var page = e.NewElement as DummyPage;
AppDelegate.DummyPageRef = page;
var view = NativeView;
// create a new window instance based on the screen size
window = new UIWindow(UIScreen.MainScreen.Bounds);
viewController = new ImageViewController();
navigationController = new UINavigationController();
navigationController.PushViewController(viewController, false);
// If you have defined a view, add it here:
//window.AddSubview(navigationController.View);
window.RootViewController = navigationController;
// make the window visible
window.MakeKeyAndVisible();
//var label = new UILabel(new CGRect(0, 40, 320, 40));
//label.Text = "2 " + page.Heading;
//view.Add(label);
}
ImageViewController page in IOS opens a galary for user to select an image, processes the selected image & when done processing calls page 3 on Forms with following
Code:
var secondViewController = App.GoToPostScanPage().CreateViewController();
NavigationController.PushViewController(secondViewController, true);
This works fine. But when I see the page 3 on forms the backstack is still pointing to my dynamic page that I created to select & process the image. How can I get rid of this IOS navigation stack & jump back to my Forms Navigation stack? Is this possible?
Thanks
Supreet

Related

Push more than 3 ViewController in NavigationController from AppDelegate App crash

I am working on Push Notification. Now When the Application is raise to Device and When I Tap on it. I want to push 3 ViewController to Navigation Stack.
So I am using below code to do this.
AppDelegate.cs Code
Window = new UIWindow(UIScreen.MainScreen.Bounds);
Menu = new SlideoutNavigationController();
var storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("DashBoardViewController") as DashBoardViewController;
Menu.MainViewController = new MainNavigationController(webController, Menu);
Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = false };
Window.RootViewController = Menu;
Window.MakeKeyAndVisible();
var storyboarddd = UIStoryboard.FromName("Main", null);
var webControllerdd = storyboarddd.InstantiateViewController("DashBoardViewController") as DashBoardViewController;
webControllerdd.reloadNotication();
UINavigationController nav = webController.NavigationController;
var notifyWebController = storyboard.InstantiateViewController("NotificationListViewController") as NotificationListViewController;
notifyWebController.navigationContoller = nav;
nav.PushViewController(notifyWebController, true);
if (type.Equals("Damage Report"))
{
var webController2 = storyboard.InstantiateViewController("DamageReportViewController") as DamageReportViewController;
webController2.DamageReportId = id;
webController2.navigationContoller = nav;
nav.PushViewController(webController2, true);
}
if (type.Equals("Overloss"))
{
var webController2 = storyboard.InstantiateViewController("OverlossViewController") as OverlossViewController;
webController2.PacketId = id;
webController2.navigationContoller = nav;
nav.PushViewController(webController2, true);
}
The upper code is working fine to open Specific ViewController.
But My App crash after it with the crash Log.
Crash Report :
2017-07-26 15:25:18.330 Aastha.iOS[6357:2021514] nested push animation can result in corrupted navigation bar
2017-07-26 15:25:18.740 Aastha.iOS[6357:2021514] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
My Solution :
When i search on google and SO someone says that Open ViewController one after another from each ViewController ViewDidAppear method but I am not sure If this is correct way.
Any Help be Appreciated.
You can't push more than one view controller with animation. If you want user to see transtions A -> B -> C you indeed have to do it in A's and B's viewDidAppear method.
If you want user to only see the last view controller C and be able to go back through A and B, you can push them all at once, but you need to do it without animation:
nav.PushViewController(webController2, false);
Another option is to use SetViewControllers like this:
nav.SetViewControllers([A, B, C], true);
this will push all 3 view controllers at the same time and only the topmost one will be animated using push transition. I don't think this fits your situation, just adding it here for completeness sake.

Flyout navigation controller menu indicator

I am using the Flyout navigation component in my Xamarin IOS application and I am able to connect multiple view controllers to it and also swipe out left and able to see the menu items. But I am not getting a menu indicator at the top as like in the drawer menu applications(like facebook and many android apps). Here is the code I used
FlyoutNavigationController navController = new FlyoutNavigationController {//this will create a new instance of the FlyoutComponent
NavigationRoot = new RootElement("Menu"){ //Here we create the root of the alements
new Section("Seccion 1"){
new StringElement("Picks"),
new StringElement("Watchlist"),
},
new Section("Seccion 2"){
new StringElement("Portfolio"),
},
},
ViewControllers = new [] {//here we link Controllers
this.Storyboard.InstantiateViewController("Picks") as UIViewController,//here we create the instances for the Controllers
this.Storyboard.InstantiateViewController("Watchlist") as UIViewController,
this.Storyboard.InstantiateViewController("Portfolio") as UIViewController,
}
};
//navController.ToggleMenu();
View.AddSubview (navController.View);
Finally I figured out that I have to set the left bar button item with an image looking like a drawer menu like this
UIBarButtonItem menuIndicator = new UIBarButtonItem (UIImage.FromBundle ("images/slideout.png"), UIBarButtonItemStyle.Plain, (sender, e) => {
AppDelegate.FlyoutNavigation.ToggleMenu ();
});
NavigationItem.SetLeftBarButtonItem (menuIndicator, false);

MonoTouch.Dialog with UISplitViewController

I'm creating universal app with MonoTouch. When running on iPad I use UISplitViewController and build multi level menu in master view (on the left side) with MonoTouch.Dialog.
Problem is, that when I touch first root element it opens new view which covers whole screen instead of being inside master split view.
Question is, how can I make so next root element opens inside same view as it's parent?
All the examples I could find usually has one level menu on the master view so when you touch it displays something on the detail view.
Hope this makes sense.
Let's say you have an UISplitViewController and your CustomViewController.
UISplitViewController split = ...;
CustomViewController controller = ...;
If you want to push the new controller on top of the current (master) one then use:
var root = new RootElement ();
var dvc = new DialogViewController (UITableViewStyle.Plain, root, true);
dvc.ActivateController (controller);
If you want to show the new controller in the details (right) section then use something like:
UISplitViewController split = ...;
var about = new StringElement ("About");
about.Tapped += delegate {
split.ViewControllers = new UIViewController [] {
split.ViewControllers [0],
controller
};
};
So you want your, I guess table, in the master to populate a new masterview on touch event?
I'm not familiar with .dialog but i've given an example as i know it:
take your rootviewcontroller.parentviewcontroller.splitviewcontroller and then populate the viewcontrollers[0]
var split =(uisplitviewcontroller)rootviewcontroller.parentviewcontroller.splitviewcontroller;
var nav = (uinavigationcontroller)split.viewcontrollers[0];
nav.pushviewcontroller(_yourView_);

Monotouch back to first ViewController

I'm having a problem going back again to my first Apps VC, the first "screen/ViewController)" is a login screen, then I call a UITabbar with their respective ViewControllers, when I'm on a certain level of a ViewController (for example the 5th one) I want to get a "Logout" behavior in my App and get back to the first ViewController (Login). But I think I can only Navigate back to the first ViewController of my Tabbar control. I was trying with this methods of my VC:
this.NavigationController.PopToViewController(previousVC,true);
or
this.NavigationController.PopToRootViewController(true);
Any help would be appreciated.
(If you need more details with the code please tell me about it)
//Call to the tab bar from the login viewcontroller
mainTBC = new TabBarMenuPpal ();
this.NavigationController.PushViewController (mainTBC, true);
…
//Tabbarmenuppal with a set of navcontrollers
public TabBarMenuPpal ()
{
var customerVC = new Customers ();
navCustomers = new UINavigationController ();
navCustomers.PushViewController (customerVC, true);
navCustomers.TopViewController.Title = customersTitle;
navCustomers.TabBarItem = new UITabBarItem (customersTitle, UIImage.FromFile ("Utility/Images/Cust-30x30.png"), 0);
…
mainVC = new UIViewController[]
{
navCustomers
, navSettings
} ;
this.ViewControllers = mainVC;
}
The problem is that when I start to navigate in the navCustomers I can't find a way to go back to the login VC (deleting my tab bar and releasing all their resources). (Sorry about my English).
I don't know if it's the best solution but I have implemented a "GoToLogin" method in my UITabBarController which only does this:
public void GoToLogin()
{
this.NavigationController.PopToRootViewController(true);
}
So when I need to go to my first page I only do this:
if(MainDialog.NavigationController.TabBarController != null)//loaded from the tab bar
((TabBarMenuPpal)MainDialog.NavigationController.TabBarController).GoToLogin();
else//loaded from the login screen
MainDialog.NavigationController.PopToRootViewController(true);

Custom Back Button in NavigationGroup (Titanium Mobile)

Developing in Titanium Mobile (latest SDK)
I have a navigationGroup with navBarHidden set to true. Within my windows, I have custom Back and Next buttons. The next button is obviously a cake walk, as it just opens a new window within the navigation group.
My question is the back button. How can I give my back button the same functionality as the default back button which iOS automatically adds to a navigationGroup?
Why you are hiding your navbar?
you declare a navigation group like this:
var nav = Titanium.UI.iPhone.createNavigationGroup({
window: win1 //win1 is window defined above
});
Now suppose you have win2(another window) on which you navigate.
so while opening that win2 just do like this
nav.open(win2,{animated:true});
by doing this the titanium will automatically add a back button on the top.
OR
you can do like this if you dont want that automatic back button
var win = Titanium.UI.currentWindow;
var b = Titanium.UI.createButton({title:'Back'});
win.leftNavButton = b;
b.addEventListener('click', function()
{
alert('I was clicked'); // to confirm its being called
// do the stuff here
win.close();
});

Resources