Tutorial :iPhone SDK Problem: load TableView whitin TabBarControlled Views



Question:

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


Solution:1

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »