Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hi this was a tough issue for me too until i saw this idea: <a href="http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller" rel="nofollow">http://www.hanspinckaers.com/custom-action-on-back-button-uinavigationcontroller</a></p> <p>When both the NavigationController and the TopViewController have the same orientation then IOS creates the following call sequence using the below code(monotouch)</p> <ul> <li>SomeTopViewController ViewWillDisappear </li> <li>WillShowViewController viewController: the new TopViewController</li> <li>SomeTopViewController ViewDidDisappear</li> <li>DidShowViewController viewController: the new TopViewController</li> </ul> <p>When the NavigationController and the TopViewController have <strong>different</strong> orientations then the NavigationController delegate is <strong>not</strong> called as you described. The call sequence is therefore:</p> <ul> <li>SomeTopViewController ViewWillDisappear </li> <li>SomeTopViewController ViewDidDisappear</li> </ul> <p>The following code reproduce the ios call sequence by overriding the NavigationController' PopViewControllerAnimated:</p> <pre><code>public class MyNavigationControllerDelegate : UINavigationControllerDelegate { public MyNavigationControllerDelegate( ) : base() {} public bool WasCalled {get;set;} // flag that we use to track whether iOS calls the handlers or we have to public override void WillShowViewController( UINavigationController navigationController, UIViewController viewController, bool animated ) { Console.WriteLine( "WillShowViewController viewController: {0}", viewController.GetType() ); WasCalled = true; // signal that we have been called //.….. do your stuff } public override void DidShowViewController( UINavigationController navigationController, UIViewController viewController, bool animated ) { Console.WriteLine( "DidShowViewController viewController: {0}", viewController.GetType() ); //.….. do your stuff } } public partial class MyNavigationController : UINavigationController { MyNavigationControllerDelegate navigationControllerDelegate; public override void ViewDidLoad() { base.ViewDidLoad(); navigationControllerDelegate = new MyNavigationControllerDelegate( viewSelectionControl ); Delegate = navigationControllerDelegate; } public override UIViewController PopViewControllerAnimated( bool animated ) { Console.WriteLine( "PopViewControllerAnimated TopViewController.GetType: {0}", TopViewController.GetType() ); navigationControllerDelegate.WasCalled = false; // reset flag before we start the popsequence UIViewController ctrl = base.PopViewControllerAnimated( animated ); AppDelegate.MainWindow.BeginInvokeOnMainThread( delegate { if( !navigationControllerDelegate.WasCalled ) { // if iOS did not call the delegate handler then we must do it Delegate.WillShowViewController( this, TopViewController, animated ); navigationControllerDelegate.WasCalled = false; // reset flag to be used in the next DidShowViewController step of the popsequence } } ); Thread t = new Thread( () =&gt; RunPop(animated) ); tt.Start(); return ctrl; } void RunPop(bool animated) { Thread.Sleep( 500 ); AppDelegate.MainWindow.BeginInvokeOnMainThread( delegate { if( !navigationControllerDelegate.WasCalled ) { // if iOS did not call the delegate handler then we must do it Delegate.DidShowViewController(this,TopViewController,animated); } } ); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload