【问题标题】:Monotouch back to first ViewControllerMonotouch 回到第一个 ViewController
【发布时间】:2012-03-05 22:25:01
【问题描述】:

我再次回到我的第一个 Apps VC 时遇到问题,第一个“屏幕/ViewController)”是一个登录屏幕,然后当我处于某个级别时,我使用它们各自的 ViewController 调用 UITabbar一个 ViewController(例如第 5 个)我想在我的应用程序中获得“注销”行为并返回到第一个 ViewController(登录)。但我想我只能导航回我的 Tabbar 控件的第一个 ViewController。我正在尝试使用我的 VC 的这种方法:

this.NavigationController.PopToViewController(previousVC,true); 或者 this.NavigationController.PopToRootViewController(true);

任何帮助将不胜感激。

(如果您需要有关代码的更多详细信息,请告诉我)

    //Call to the tab bar from the login viewcontroller
    mainTBC = new TabBarMenuPpal ();
this.NavigationController.PushViewController (mainTBC, true);
…

//Tabbarmenuppal with a set of navcontrollers 
public TabBarMenuPpal ()
{
    var customerVC = new Customers ();
    navCustomers = new UINavigationController ();
    navCustomers.PushViewController (customerVC, true);
    navCustomers.TopViewController.Title = customersTitle;
    navCustomers.TabBarItem = new UITabBarItem (customersTitle, UIImage.FromFile ("Utility/Images/Cust-30x30.png"), 0);
    …
    mainVC = new UIViewController[]
    {
          navCustomers
        , navSettings
    } ;
    this.ViewControllers = mainVC;
}

问题是当我开始在 navCustomers 中导航时,我找不到返回登录 VC 的方法(删除我的标签栏并释放所有资源)。 (对不起我的英语)。

【问题讨论】:

  • 您能显示您的特定设置的代码吗?你使用的是 UITabBarController 还是 UINavigationController?
  • 一般来说,您可能需要在 AppDelegate 上公开一个方法,该方法将清理选项卡、导航栏和视图,然后显示您的登录 UI。

标签: ios uiviewcontroller xamarin.ios uitabbar


【解决方案1】:

我不知道这是否是最好的解决方案,但我在我的 UITabBarController 中实现了一个“GoToLogin”方法,它只执行此操作:

public void GoToLogin()
{
   this.NavigationController.PopToRootViewController(true);
}

所以当我需要访问我的第一页时,我只会这样做:

if(MainDialog.NavigationController.TabBarController != null)//loaded from the tab bar
              ((TabBarMenuPpal)MainDialog.NavigationController.TabBarController).GoToLogin();
else//loaded from the login screen  
              MainDialog.NavigationController.PopToRootViewController(true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    相关资源
    最近更新 更多