Nathan
Nathan

Reputation: 666

presentViewController not showing tabbar

I have an iPhone application that uses a tabbar on all my views. Also, my first view controller has no navigationBarController but my second view does, as well as the tabbar.

My second view controller is a tableview and when I click on one of the cells, I want to be taken to the first view controller (passing along a parameter with it).

I've tried a few ways of doing with, which all kinda work, but don't.

secondViewController.m
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:[NSBundle mainBundle]];
[firstViewController passThisAlong:@"id"];

//[self presentViewController:firstViewController animated:YES completion:nil]; //1
[self.navigationController pushViewController:firstViewController animated:YES]; //2
//[self.tabBarController presentViewController:firstViewController animated:YES completion:nil]; //3
[firstViewController release];
firstViewController = nil;

So as you can see above, I've tried 3 different methods of getting to the first view controller. The second one loads the first view, drilled down inside the second view, as it keeps the nagigationBarController (even though first view doesn't have one) with the back button to the second view.

The other two do the same thing as each other. Which is it goes to the first view (without a navigationBar), but, there is no tabbar and the content of the first view has been shifted up about the height of the tabbar, and in it's place is just blackness.

I hope this all makes sense. I just want to be able to go from my second view when someone selects a cell in the table, to my first view as if I'd clicked the icons in the tabbar.

I've seen in the docs 'On iPhone and iPod touch, the presented view is always full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.' not sure if this is related to my issue and if so, if there's a way around it.

Many thanks,

Upvotes: 0

Views: 4324

Answers (2)

Nina
Nina

Reputation: 1699

Present modal view works this way. And why can't you use a Tab based application?

Upvotes: 1

Lucas
Lucas

Reputation: 6729

It's normal, a modal View is supposed to work this way

From Apple Documentation

The ability to present view controllers is a tool that you have at your disposal for interrupting the current workflow and displaying a new set of views. Most commonly, an app presents a view controller as a temporary interruption in order to obtain key information from the user. However, you can also use presented view controllers to implement alternate interfaces for your app at specific times.

In your didSelectRowAtIndexPath you can use something like

YourAppNameDelegate *appDelegate = (YourAppNameDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabBarController].selectedIndex = 0;

Upvotes: 1

Related Questions