2014-01-07 31 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; 
}