How within a tab bar controller do I segue from one view controller to another and retain the tab bar?

主宰稳场 提交于 2019-11-29 09:56:55

问题


I have an application with several view controllers controlled from a tab bar controller. From one of these view controllers I want to (on clicking a button) segue to another view controller and retain the tab bar at the bottom of the segued to view.

I've used

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"newView"]){
        UIViewController *controller =segue.destinationViewController;
        controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentModalViewController:controller animated:YES];
    }
 }

This works fine except the tab bar is missing from the segued to view (a placeholder shows for it in the storyboard, but it doesn't show up when the app is run) I've also tried replacing

[self presentModalViewController:controller animated:YES];

with

[self presentViewController:controller animated:YES completion:nil];

but that doesn't work either.

A bit of debugging shows that for the segued-to view controller, the tabBarController property is set to nil.

Is there anyway to retain the tab bar in the segued-to view controller?


回答1:


From your explanation, I don't think you want a modal controller. Modal is used to overlay, rendering your tab bar useless. From your storyboard, select your segue and select push, not modal.

Push vs Modal (Note the tab bar):



来源:https://stackoverflow.com/questions/9694724/how-within-a-tab-bar-controller-do-i-segue-from-one-view-controller-to-another-a

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