2014-01-07 30 views
3

我正在使用mvvmcross並在後面的代碼中實現視圖的接口。我想隱藏導航欄,但我還沒有找到解決方案。使用Mvvmcross隱藏Xamarin項目中的導航欄

我試圖

NavigationController.SetNavigationBarHidden(true, false); 

NavigationController.NavigationBarHidden = true; 

在不同的方法(ViewDidAppear和viewWillAppear中),但他們沒有對UI的影響。

也許有人可以給我一個提示。 :-)

@Edit:一些詳細信息:

我AppDelegate.cs

[Register("AppDelegate")] 
public partial class AppDelegate : MvxApplicationDelegate 
{ 
    UIWindow _window; 

    public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
    { 
     _window = new UIWindow(UIScreen.MainScreen.Bounds); 

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

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

     _window.MakeKeyAndVisible(); 

     return true; 
    } 
} 

另外我使用的是基本視點類從MvxViewController繼承。

回答

0

這將殺死它,讓我知道如果你有問題。

[Register ("AppDelegate")] 
public partial class AppDelegate : UIApplicationDelegate 
{ 
    // class-level declarations 
    UIWindow window; 
    MyViewController viewController; 
    MainViewController mainViewController; 
    UINavigationController navController; 

    public UINavigationController NavController { get { return navController; }} 

    // 
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window 
    // visible. 
    // 
    // You have 17 seconds to return from this method, or iOS will terminate your application. 
    // 
    public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
    { 
     var navController = new UINavigationController(); 
     navController.SetNavigationBarHidden (true, false); 

     window = new UIWindow (UIScreen.MainScreen.Bounds); 
     viewController = new MyViewController(); 

     app.SetStatusBarStyle (UIStatusBarStyle.LightContent, true); 

     navController.PushViewController(viewController, false); 

     window.RootViewController = navController; 
     window.MakeKeyAndVisible(); 

     return true; 
    } 
} 

}

+0

感謝您的幫助,但我無法實施您的解決方案。 在我的AppDelegate.cs我使用 var setup = new Setup(this,_window); setup.Initialize(); var startup = Mvx.Resolve (); startup.Start();' 我正在使用從MvxViewController繼承的抽象BaseView類。 – Cray

5

好了,發現自己的解決方案:

只需粘貼下面的代碼到viewDidLoad方法在MvxViewController類(在許多mvvmcross教程例子FirstView.cs):

var navController = base.NavigationController; 
navController.NavigationBarHidden = true; 
0

默認演示者在窗口上爲RootController使用UINavigationController;所以你可以在AppDelegate全局操縱導航欄,通過從窗口抓取它並投射:

public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
{ 
    window = new UIWindow(UIScreen.MainScreen.Bounds); 

    new Setup(this, window).Initialize(); 
    Mvx.Resolve<IMvxAppStart>().Start(); 

    var navigationBar = ((UINavigationController)window.RootViewController).NavigationBar; 
    navigationBar.BackgroundColor = UIColor.Black; 
    navigationBar.BarTintColor = UIColor.Black; 
    navigationBar.TintColor = UIColor.White; 

    window.MakeKeyAndVisible(); 

    return true; 
}