XIB 中的导航栏项,显示 StoryBoard 选项卡栏根视图控制器 Segue [英] Nav Bar Item in XIB that Presents a StoryBoard Tab Bar Root View Controller Segue

查看:43
本文介绍了XIB 中的导航栏项,显示 StoryBoard 选项卡栏根视图控制器 Segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有很多事情要做,哈哈.在我的主菜单上,如果您单击聊天",它将带您进入聊天 XIB.

My App has a lot going on with it, lol. On my Main Menu, if you click "Chat", it will take you to the Chat XIB.

如果你看导航栏的左上角,我有一个叫做主菜单"的东西.我希望这能带我回到主菜单.我的主菜单在 main.Storyboard 上.聊天是一个 XIB.两个视图都有标签栏.我一整天都在兜圈子,试图弄清楚这一点.这是我尝试过的最后一件事崩溃了:

If you look to the top left in the Navigation Bar I have something called "Main Menu". I want this to take me back to the Main Menu. My Main Menu is on the main.Storyboard. The Chat is an XIB. Both Views have Tab Bars. I've been going in circles all day trying to figure this out. This is the last thing I have tried which crashes:

-(void)MainMenu
{
    MainMenuTabBarControllerViewController *MMTBC = [[MainMenuTabBarControllerViewController alloc]init];
    [self.navigationController popToViewController:MMTBC animated:YES];
}
- (void)viewDidLoad
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
    [super viewDidLoad];

    self.title = @"Group";
    //---------------------------------------------------------------------------------------------------------------------------------------------
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New" style:UIBarButtonItemStylePlain target:self
                                                                             action:@selector(actionNew)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Main Menu" style:UIBarButtonItemStyleBordered target:self action:@selector(MainMenu)];

    //---------------------------------------------------------------------------------------------------------------------------------------------
    self.tableView.tableFooterView = [[UIView alloc] init];
    //---------------------------------------------------------------------------------------------------------------------------------------------
    chatrooms = [[NSMutableArray alloc] init];
}

推荐答案

因为您的应用程序中有两个选项卡栏控制器.我认为使用导航控制器(推送/弹出)来管理它们之间的转换不是一个好主意.尝试使用 presentViewController.

Since you have two tab bar controllers in your application. I don't think it is a good idea to use navigation controller (push/pop) to manage the transition between them. Try with presentViewController.

当聊天按钮被按下时,显示第二个选项卡视图控制器.

When the chat button is pressed, show the second tab view controller.

- (IBAction)chatButtonPressed:(id)sender {
    ChatTabBarController *chatTabView = ... // allocate memory and initialize
    [self presentViewController:chatTabView animated:YES completion:nil];
}

按下主菜单按钮后,将其关闭.

When the main menu button is pressed, dismiss it.

- (IBAction)mainMenuButtonPressed:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

注意到几年前有人问过一个非常相似的问题.看看这个:

Just notice a very similar question being asked a couple of years ago. Take a look at this one:

如何在目标 c 中单击视图中的按钮后推送标签栏控制器?

这篇关于XIB 中的导航栏项,显示 StoryBoard 选项卡栏根视图控制器 Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆