XIB 中的导航栏项目,呈现故事板选项卡栏根视图控制器 Segue
Nav Bar Item in XIB that Presents a StoryBoard Tab Bar Root View Controller Segue
我的应用程序有很多问题,哈哈。在我的主菜单上,如果您单击 "Chat",它将带您进入聊天 XIB。
如果您查看导航栏的左上角,我有一个名为 "Main Menu" 的东西。我想让它带我回到主菜单。我的主菜单在 main.Storyboard 上。聊天是一个 XIB。两个视图都有标签栏。我整天都在兜圈子试图弄清楚这一点。这是我最后一次尝试崩溃的事情:
-(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];
}
你应该使用故事板。尝试删除 XIB 并开始在故事板上使用 Unwind segue
。您使用的是推送还是模态?它改变了一切。迁移到 Storyboard 后,请阅读 Apple 关于 Unwind segues 的文档。
此致,
因为您的应用程序中有两个标签栏控制器。我认为使用导航控制器 (push/pop) 来管理它们之间的转换不是一个好主意。尝试 presentViewController。
按下聊天按钮时,显示第二个选项卡视图控制器。
- (IBAction)chatButtonPressed:(id)sender {
ChatTabBarController *chatTabView = ... // allocate memory and initialize
[self presentViewController:chatTabView animated:YES completion:nil];
}
按下主菜单按钮时,将其关闭。
- (IBAction)mainMenuButtonPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
编辑:
请注意几年前有人问过一个非常相似的问题。看看这个:
How can I push tab bar controller after click a button from a view in objective c?
我的应用程序有很多问题,哈哈。在我的主菜单上,如果您单击 "Chat",它将带您进入聊天 XIB。
如果您查看导航栏的左上角,我有一个名为 "Main Menu" 的东西。我想让它带我回到主菜单。我的主菜单在 main.Storyboard 上。聊天是一个 XIB。两个视图都有标签栏。我整天都在兜圈子试图弄清楚这一点。这是我最后一次尝试崩溃的事情:
-(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];
}
你应该使用故事板。尝试删除 XIB 并开始在故事板上使用 Unwind segue
。您使用的是推送还是模态?它改变了一切。迁移到 Storyboard 后,请阅读 Apple 关于 Unwind segues 的文档。
此致,
因为您的应用程序中有两个标签栏控制器。我认为使用导航控制器 (push/pop) 来管理它们之间的转换不是一个好主意。尝试 presentViewController。
按下聊天按钮时,显示第二个选项卡视图控制器。
- (IBAction)chatButtonPressed:(id)sender {
ChatTabBarController *chatTabView = ... // allocate memory and initialize
[self presentViewController:chatTabView animated:YES completion:nil];
}
按下主菜单按钮时,将其关闭。
- (IBAction)mainMenuButtonPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
编辑:
请注意几年前有人问过一个非常相似的问题。看看这个:
How can I push tab bar controller after click a button from a view in objective c?