views:

27

answers:

1

Hi

I'm getting better and better with doing things for the iPhone in xcode, but here I have ran into a dead end.

I'm trying to build an app with two views: the main one and one for settings. I want to be able to switch between the two of them. Since I need every pixel in the main view I have built a switchView class that simply switch between the two views when I press a button (so much smaller than a tabView), which is working fine.

Now I'm a bit deeper in development and want the settings view to be a table view from where I can navigate to the next level of detail. I have done this before, but without the switch view.

My problem is that I get the table view (in settings) to work, but once I try to push my view controller nothing happens. While debugging I can see that it works through the code (eg didSelectRowAtIndexPath is working) but no new view pops up. Neither any error message.

I have the switchView added in my MainWindow.xib and then do a [window addSubview:switchViewController.view]; in my AppDelegate to load the main view.

Where should I put the root controller for the navigation for the table view? Because I guess that's the problem I have?

Below the code that results in nothing...

ViewsAppDelegate *delegate =[[UIApplication sharedApplication] delegate];

    [delegate.settingsNavController pushViewController:settingsDetailViewController animated:YES];

Happy for any suggestions that could lead me to the right track. Spent way too much time to solve this.

A: 

I might be misunderstanding what you're after, but let me try...

When you created your project you should have gotten your MainViewController and an AppDelegate both spun up and created for you. From the snippet you've provided it looks to me like your instantiating a new (and possibly second) app delegate from within your MainViewController.

Rather than doing this, I would suggest that you move your NavigationController up one level to the AppDelegate supplied by the SDK. Then in your MainViewController, add the existing AppDelegate as an IBOutlet and tie them all together in IB. Once you've done that, using the navigation controller should go much more smoothly.

For example, my MainWindow.xib has several objects, and I've highlighted the two that I think you're probably concerned with...

http://www.freeimagehosting.net/uploads/f50268da03.png

*Sorry for the link - I can't post images yet.

Then, from my AppDelegate I customize my applicationDidFinishLaunchingWithOptions like so...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

  navController.viewControllers = [NSArray arrayWithObject:mainMenuController];

  // Override point for customization after app launch    
  [window addSubview:navController.view];
  [window makeKeyAndVisible];

  return YES;
}

That keeps the navController up at the highest level (where I think it belongs) and allows you to push and pop views throughout the entire app while keeping that history of what's on the stack.

Hope that helps - I might have completely misunderstood what you were after.

Good Luck! Bob

Bobby B
Thanks BobbyWhat I'm trying to achieve (even if I might have started it off in the wrong way) is something like in Apples Weather App. You have a main screen and once you click on the small i you get to the settings screen. On that screen I would like to have a tableView with drill down navigation. So I started with a normal Windows based app and then switched between two views. Worked good. But when I wanted to add drill down tableView in one of the views i got ( and still is) stuck.Maybe I should try out the Utility based template...???
Structurer
I would encourage you to consider checking out the View Based template and then some tutorials on how to use a navigation controller.There's some quick free ones out on the web (http://www.youtube.com/watch?v=9ozwoETFei0) and if you don't mind spending some money ($5) the guys over at Pragmatic Programmers have a really nice iPhone SDK tutorial series (http://pragprog.com/screencasts/v-bdiphone/writing-your-first-iphone-application). The second episode would be perfect for this.With that knowledge you should be able to modify what you have pretty quickly.Good luck!
Bobby B
ThanksI must have been dehydrated or something last week. Nothing was really working but sorted out now. Thanks for your replies and support!
Structurer