2016-11-13 12 views
0

MvvmCrossのPresenterクラスが初期化しているように見えても、NavigationControllerがどこにでもアクセスできるようにする理由を誰かが説明できますか?NavigationControllerがnull

ベローは私の現在のコードですが、NavigationControllerを取得するには複数の方法を試しましたが、いずれも機能しませんでした。

これは、アプリの最初の画面(ログイン)で非表示にすることを目的としています。 これを達成するには?それはその時点でUINavigationViewControllerに添付されていないためNavigationControllerプロパティは、コンストラクタにヌルされている理由として

AppDelegate.cs

[Register("AppDelegate")] 
public class AppDelegate : MvxApplicationDelegate 
{ 
    private UIWindow window; 

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) 
    { 
     window = new UIWindow(UIScreen.MainScreen.Bounds); 
     var presenter = new MvxIosViewPresenter(this, window); 

     var setup = new Setup(this, presenter); 
     setup.Initialize(); 

     var startup = Mvx.Resolve<IMvxAppStart>(); 
     startup.Start(); 

     window.MakeKeyAndVisible(); 

     return true; 
    } 
} 

LoginScreen.cs

public partial class LoginScreen : MvxViewController 
{ 
    private UITabBarController tabBarController; 

    public new LoginViewModel ViewModel 
    { 
     get { return (LoginViewModel)base.ViewModel; } 
     set { base.ViewModel = value; } 
    } 

    public LoginScreen() 
    { 
     NavigationController.SetToolbarHidden(true, false); 

     tabBarController = new UITabBarController(); 
     tabBarController.View.Frame = new CGRect(0, 0, View.Bounds.Width, 450); 

     var tab1 = new UIViewController(); 
     tab1.Title = "tab1"; 
     tab1.View.BackgroundColor = UIColor.Green; 
     var tab2 = new UIViewController(); 
     tab2.Title = "tab2"; 
     tab2.View.BackgroundColor = UIColor.Orange; 
     var tab3 = new UIViewController(); 
     tab3.Title = "tab3"; 
     tab3.View.BackgroundColor = UIColor.Red; 

     tabBarController.ViewControllers = new UIViewController[] { tab1, tab2, tab3 }; 

     var cgrect = new CGRect(0, 510, View.Bounds.Width, 45); 
     var button = new UIButton(UIButtonType.Custom) 
     { 
      BackgroundColor = UIColor.Green, 
     }; 
     button.SetTitle("click", UIControlState.Normal); 
     button.Frame = cgrect; 

     View.AddSubviews(new UIView[] { tabBarController.View, button }); 

     var swipeLeft = new UISwipeGestureRecognizer(HandleLeftSwipe) 
     { 
      Direction = UISwipeGestureRecognizerDirection.Left 
     }; 
     var swipeRight = new UISwipeGestureRecognizer(HandleRightSwipe) 
     { 
      Direction = UISwipeGestureRecognizerDirection.Right 
     }; 
     tabBarController.View.AddGestureRecognizer(swipeLeft); 
     tabBarController.View.AddGestureRecognizer(swipeRight); 
    } 

答えて

1

理由ライフサイクルの

あなたは、好ましくは、ViewDidLoad

+0

恐ろしいのオーバーライドの内側にUIを設定する必要があります!私はすでにそれを試みたが、コンストラクタからすべてを移動した後にNavigationControllerがもうnullではないようだという強い思いがあった。今問題は隠されていないということだけです。どうしてこれが起こるのか分かりませんか? –

+0

SetToolbarHiddenの代わりにSetNavigationBarHiddenメソッドを使う必要があると思います。 – Cheesebaron

+0

次の時間にもっと注意を払う必要があり、最初の問題で迷子になってしまったので、これではあまり考えなかった。 Xamarinコミュニティの貢献に感謝し、多くの有益な情報を見つけました! –

関連する問題