简体   繁体   English

在iOS中显示新视图和标签栏控制器

[英]Displaying a new view and Tab Bar Controller in iOS

I am trying to achieve the following but dont know the best way to go about it so any tips would be great. 我正在尝试实现以下目标,但不知道解决该问题的最佳方法,因此任何技巧都很棒。

My app has a first root view which has a tab bar with 4 tabs, one of the tabs contains a table view. 我的应用程序具有第一个根视图,该视图具有一个带有4个选项卡的选项卡栏,其中一个选项卡包含一个表格视图。 When an item is selected on the table view I want to display a details page (which I can do fine) but also completely change the tab bar to match the new set of data. 当在表视图中选择一个项目我想显示详细信息页面(我可以做得很好),而且还彻底改变标签栏以匹配新的数据集。

A good example of this is the free F1 2011 app. 免费的F1 2011应用就是一个很好的例子。 When selecting "Live Timing" you are taken to a new screen with a different tab bar (with a home button at the top to get back to previous screen.) 选择“实时计时”时,您将进入一个带有其他选项卡栏的新屏幕(顶部带有主页按钮,可返回上一屏幕)。

How would be the best way to go about implementing this? 实现此目标的最佳方法是什么?

Thanks in advance. 提前致谢。

Fraser 弗雷泽

Try linking the the view controller with the table to the new UITabBarController and make it a modal segue. 尝试将带有表的视图控制器链接到新的UITabBarController并将其设置为模式选择。 In the class for your viewcontroller with the table do an 在您的带表的viewcontroller的类中,

#import "FirstViewControllerInNewTabBar"

Then in the 然后在

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

method you will want to do the following: 方法,您将需要执行以下操作:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    // Since your segue is pointing to the new tab bar controller
    UITabBarController *tabBarController = (UITabBarController *)segue.destinationViewController;  

    // Now you want to pass data into the new tab bar's view controllers
    FirstViewControllerInNewTabBar *vc = (FirstViewControllerInNewTabBar *)[tabBar.viewControllers objectAtIndex:0];

    // Assuming FirstViewControllerInNewTabBar has a property 'NSString *dataToPassIn'
    vc.dataToPassIn = @"Potato";
}

只需在didSelectRowAtIndexpath:方法中创建一个新的tabbarcontroller视图(就像在应用程序委托中所做的那样)。

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

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