有人可以解释一下为什么我想在任何地方获取NavigationController null,即使MvvmCross的Presenter类似乎初始化了一个吗?
Bellow是我目前的代码,我尝试了多种方法来获取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);
}
答案 0 :(得分:1)
构造函数中NavigationController
属性为空的原因是因为它在生命周期的那一点没有附加到UINavigationViewController
。
您最好在覆盖ViewDidLoad