简体   繁体   English

跨TabBarController在嵌套的视图控制器之间导航-Xamarin iOS

[英]Navigate between nested View Controllers across a TabBarController - Xamarin iOS

I'm having trouble with navigation outside of the typical use cases for navigation controllers and tabbar controllers. 我在导航控制器和标签栏控制器的典型用例之外无法进行导航。 Here's a drawing of a simplified version. 这是简化版本的图纸。 (real version has a TabBarController that feeds into 9 NavControllers) (真实版本有一个TabBarController,可导入9个NavController)

AppNavigation

In my Home Nav Controller, there's a table view where the user could select a row and that should navigate them to a particular Events Detail View Controller. 在我的Home Nav Controller中,有一个表格视图,用户可以在其中选择一行,并将其导航到特定的Event Detail View Controller。 At that point, the user should be able to navigate back to the Events TableView Controller to see the list of events or use the TabBar to navigate to another section. 那时,用户应该能够导航回事件TableView Controller以查看事件列表,或者使用TabBar导航到另一部分。

So far with my code I can push the correct detail view controller and select the correct index of the tabbar but it only works the first time: 到目前为止,使用我的代码,我可以推送正确的详细信息视图控制器并选择标签栏的正确索引,但这仅在第一次时有效:

 public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
     {
         tableView.DeselectRow(indexPath, true);

         var eventsDetailView = new EventsDetailController(eventPosts[indexPath.Row]);
         //loop through ViewControllers array in case the user has set a custom tabbar order via the More Tab  
         foreach (UIViewController viewC in tbController.ViewControllers)
         {
             UINavigationController navController = viewC as UINavigationController;

             if (navController.TabBarItem.Tag.Equals(9))
             {
                 navController.PushViewController(eventsDetailView, false);       
                 tbController.SelectedIndex = 9;
             }                  
         }
     }

After the user has navigated to the events detail view controller, if they then: 用户导航到事件详细信息视图控制器后,如果满足以下条件,则:

  1. travel to the Home ViewController via the TabBar 通过TabBar转到Home ViewController

  2. select a new TableRow to navigate to a different Events detail view controller ... then the same previous events detail view shows up. 选择一个新的TableRow导航到其他“事件详细信息视图”控制器...然后将显示相同的先前事件详细信息视图。 It doesn't matter which row the user selects in the Home View Controller. 用户在Home View Controller中选择哪一行都没有关系。 The initial detail view controller will always be the same one to be presented. 初始详细视图控制器将始终与要呈现的控制器相同。

Any help pointing me in the right direction would be greatly appreciated! 向我指出正确方向的任何帮助将不胜感激!

Solution: 解:

In my understanding, what you want is : 据我了解,您想要的是:

HomePageController --> EventDetailPage --> EvevtTableViewControll HomePageController > EventDetailPage > EvevtTableViewControll

So in the first step, you could push to EventDetailPage in HomePageController : 因此,在第一步中,您可以在HomePageController推送到EventDetailPage

this.NavigationController.PushViewController(new HomeDetailUIViewController(), true);

Then, in your EventDetailPage , you can customize a back button, for example: 然后,在EventDetailPage ,您可以自定义后退按钮,例如:

   UIBarButtonItem backBtn = new UIBarButtonItem();
   backBtn.Title = "back";
   backBtn.Style = UIBarButtonItemStyle.Plain;
   this.NavigationItem.LeftBarButtonItem = backBtn;

   backBtn.Clicked += (sender, e) =>
   {
       // 1 here is an example, it should be the index of your EvevtTableViewControll
       NavigationController.TabBarController.SelectedIndex = 1;
       NavigationController.PopToRootViewController(true);
   };

Set the NavigationController.TabBarController.SelectedIndex=1 first to make sure EvevtTableViewControll will show after you back from EvevtDetailViewControll , then your PopToRootViewController to back to the EvevtTableViewControll . 设置NavigationController.TabBarController.SelectedIndex=1首先确保EvevtTableViewControll后,您会显示从后EvevtDetailViewControll ,那么你的PopToRootViewController备份到EvevtTableViewControll

Try it and let me know if you have any problem. 尝试一下,让我知道您是否有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM