Nav Bar Item in XIB that Presents a StoryBoard Tab Bar Root View Controller Segue

北慕城南 提交于 2019-12-12 03:23:43

问题


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.

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];
}

回答1:


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];
}

Edit:

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

How can I push tab bar controller after click a button from a view in objective c?




回答2:


You should use storyboards. Try deleting your XIB and start using an Unwind segue on your storyboard. Are you using push or modal? It changes everything. After you migrate to storyboards, read Apple's docs on Unwind segues.

Best regards,



来源:https://stackoverflow.com/questions/28139754/nav-bar-item-in-xib-that-presents-a-storyboard-tab-bar-root-view-controller-segu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!