views:

71

answers:

1

Hi there,

I've a problem and cannot find a solution to the whole day now. I'm new to iPhone SDK, so I guess I'm just missing something.

My app consists of a TabbedNavigation, having three ViewControllers. Everything works as expected. Now I want to open a new view (preferably from a NIB) when the user tabs a button (not the tab buttons...). The button's action method is called as expected. However, I don't get the new (table-)view loaded.

I try to give you some code that explains my situation:

First, in my Application's delegate's didFinishLaunchingWithOptions I load the tabBarController's view (the TabBarController is a property of the delegate):

 // Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

The first ViewController of the TabController is shown when the app is startet, as expected. This viewController has its custom ViewController class in which the action-method for the button sits. My action method looks like this:

-(IBAction)filtersButtonPressed:(id)sender {

  FiltersTableViewController *filtersViewController = 
    [[FiltersTableViewController alloc] initWithNibName:@"Filters" bundle:nil];

  [[[super tabBarController] navigationController] pushViewController:filtersViewController];
}

This, somehow, is not working... I have tried several things of course - with no success.

Can someone of you guys point me in the right direction? It cannot be that hard just to get to a new view by the press of a button...

Thanks in advance!

Chers, pawi

A: 

Suggest you try showing the new "Filters" view as a modal view controller. Try changing your code to:

-(IBAction)filtersButtonPressed:(id)sender {

   FiltersTableViewController *filtersViewController = 
      [[FiltersTableViewController alloc] initWithNibName:@"Filters" bundle:nil];
[self presentModalViewController:filtersViewController animated:YES];

This will slide up the filters view controller (although you can change the animation effect if you want) on top of your current view. To get rid of this, when the user has finished with the view, call

[self dismissModalViewControllerAnimated:YES];

Edit: If you really want to use the navigation controller to push the view onto the stack, use

[self.navigationController pushViewController:filtersViewController];
h4xxr
Hey h4xxr, You already saved my day, after 10 mins after starting to work ;-)The trick was to use the presentModalViewController-method. I don't really see the difference between this and using the navigationController. From what I read I guess it's pushing the view to the front in fullscreen, thus overwriting the tabBar-Views.BTW: Using the self.navigationController pushViewController method does not work.Thanks for your quick help!Cheerz, pawi
pawi
Glad that helped. If self.navigationController doesn't work, check that you're all connected up properly in the NIB file...
h4xxr