2016-06-11 121 views
0

我正尝试使用iOS 7/8样式模糊视图控制器,该视图控制器通过xamarin与故事板界面出现在视图控制器上,并将其连接到导航控制器上,但我想实现的是用户必须首先登录,因此理论上菜单不应该先出现,但我希望我的登录故事Board文件。如何以编程方式设置视图控制器

其中xamarin在此基础上https://github.com/romaonthego/REFrostedViewController

// Override FinishedLaunching. This executes after the app has started. 

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

     // ViewControllers 
     var aRootVC = new DEMOHomeViewController(); 
     var secondVC = new loginViewController(); 
     var loginViewControl = new loginViewController(); 

     //define the menu structure 
     var sections = new List<REMenuItemSection>() 
     { 

      new REMenuItemSection() 
      { 
       Items = new List<REMenuItem>() 
       { 
        new REMenuViewControllerItem() 
        { 
         //View exisiting view controller, will be reused everytime the item is selected 
         Icon = UIImage.FromBundle(@"home-48"), 
         Title = @"Home", 
         ViewController = loginViewControl, 
        }, 
        new REMenuViewControllerItem() 
        { 
         //New view controller, will be reused everytime the item is selected 
         Icon = UIImage.FromBundle(@"about-48"), 
         Title = @"Payments Missed", 
         ViewController = secondVC, 
        }, 
        new REMenuViewControllerItem() 
        { 
         //New view controller, will be reused everytime the item is selected 
         Icon = UIImage.FromBundle(@"about-48"), 
         Title = @"Payments Made", 
         ViewController = secondVC, 
        }, new REMenuViewControllerItem() 
        { 
         //New view controller, will be reused everytime the item is selected 
         Icon = UIImage.FromBundle(@"about-48"), 
         Title = @"Upload Doucments", 
         ViewController = secondVC, 
        }, 

         new REMenuViewControllerItem() 
        { 
         //New view controller, will be reused everytime the item is selected 
         Icon = UIImage.FromBundle(@"about-48"), 
         Title = @"Update Info", 
         ViewController = secondVC, 
        }, 

         new REMenuViewControllerItem() 
        { 
         //New view controller, will be reused everytime the item is selected 
         Icon = UIImage.FromBundle(@"about-48"), 
         Title = @"Amend I & E", 
         ViewController = secondVC, 
        } 
       }, 
      }, 
      new REMenuItemSection() 
      { 
       Title = "Friends Online", 
       Items = new List<REMenuItem>() 
       { 
        new REMenuActionItem() 
        { 
         //Action is called, on the UI thread, everytime the item is selected 
         Icon = UIImage.FromBundle(@"ask_question-48"), 
         Title = @"Logout", 
         Command =()=> 
         { 
          var uiAlert = new UIAlertView("Logout","Are you sure you want to log out?",null,"No","Yes"); 
          uiAlert.Show(); 
         }, 
        }, 
       }, 
      }, 
     }; 

内置AC尖锐libary但是,当我打开它去我的登录查看它说以下

无法隐式转换类型UI套件视图控制器,因为它期望ui视图并且不能查看所以如何让我的登录屏幕出现在菜单显示之前

enter image description here

enter image description here

我登录查看班级

public partial class loginViewController : UIView 
{ 
    const string serviceId = "ApertureBel"; 
    NSError error; 
    LAContext context = new LAContext(); 

    partial void touchButton(UIButton sender) 
    { 
     //Lets double check the device supports Touch I 
     if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out error)) 
     { 
      var replyHandler = new LAContextReplyHandler((success, error) => 
       { 
        InvokeOnMainThread(() => 
         { 
          if (success) 
          { 
       //    var homeScreen = (UIViewController)Storyboard.InstantiateViewController("welcome"); 
       //    PresentViewController(homeScreen, true,() => { }); 
          } 
          else 
          { 
           var alert = new UIAlertView("Finger Print!", "Sorry Finger Print is not on file.", null, "Aperturer", null); 
           alert.Show(); 
          } 
         }); 
       }); 
      context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Logging in with Touch ID", replyHandler); 
     } 
     else 
     { 
      var alert = new UIAlertView("Error", "TouchID not available", null, "Aperture", null); 
      alert.Show(); 
     } 
    } 


    bool CheckLogin(string username, string password) 
    { 
     if (password == Helpers.KeychainHelpers.GetPasswordForUsername(username, serviceId, true) && username == NSUserDefaults.StandardUserDefaults.ValueForKey(new NSString("username")).ToString()) 
      return true; 
     else 
     { 
      return false; 
     } 
    } 


    // partial void buttonLoginClick(UIButton sender) 
    //{ 
    // if (string.IsNullOrEmpty(txtUserName.Text) | string.IsNullOrEmpty(txtPassword.Text)) 
    // { 
    //  var alert = new UIAlertView("Oops!", "You must enter both a username and password", null, "Oops", null); 
    //  alert.Show(); 
    //  return; 
    // } 

    // if (CheckLogin(txtUserName.Text, txtPassword.Text)) 
    // { 
    //  var homeScreen = (UIViewController)Storyboard.InstantiateViewController("welcome"); 
    //  PresentViewController(homeScreen, true,() => { }); 
    // } 
    // else 
    // { 
    //  var alert = new UIAlertView("Login problem", "wrong username", null, "Oops...again", null); 
    //  alert.Show(); 
    // } 
    //} 
} 
} 

回答

0

我有相同的逻辑,你的代码。 就我而言,我在登录之前隐藏了导航控制器。

使用此代码在您的LoginViewController当你第一次加载 页面(如果用户没有登录后隐藏。)

this.NavigationController.SetNavigationBarHidden(true, true);//hide nav

当你登录成功,显示导航控制器!

this.NavigationController.SetNavigationBarHidden(false, true);//show nav 因此,您不需要更改菜单中的代码〜

相关问题