UINavigationController with presentModalViewController - iphone

I have a menu screen that implements UINavigationController and on top of that screen, using presentModalViewController, I place another screen on which I want to have another UINavigationController. I have tried to implement another navigation controller to handle the new screen but I either get a navbar 1/8th the way down the screen and it crashes or nothing at all. I have tried [[UINavigationController alloc] initWithRootViewController:navigationConroller] with no success as well. I'm just using pushViewController to try and place the next nib on the stack which doesn't work. What am I doing wrong?

Although there are a lot of people saying on forums that Apple doesn't allow this I have got it to work. What you have to do is:
Map *mapScreen = [[[Map alloc] init] autorelease];
mapScreen.delegate = self;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:mapScreen] autorelease];
[self presentModalViewController:navController animated:YES];

Related

No effect on setViewController:animiated:?

Basically I have
ViewControllerA *aVC = [[ViewControllerA alloc] init];
ViewControllerB *bVC = [[ViewControllerB alloc] init];
UITabBarController *tabBarVC = [[UITabBarController alloc] init];
[tabBarVC setViewControllers:[[NSArray alloc] initWithObjects:aVC, bVC, nil] animated:YES];
Now I can see the two tabs on the tabBarController but when I switch from one tab to another, I can't see any effects, neither on simulator or on real device. From the documentation I should be able to see fading right? Did I miss anything?
If you pass YES to setViewControllers:animated:, UITabBarController will animate the insertion of the the new tab bar items in the tab bar. It doesn't animate the transition between view controllers if the user then switches from one tab to another.

How to display NavigationController-background within a UIPopoverController on iPhone

How can i display the background of the NavigationController (including title/buttons) in my UIPopovercontroller on the iPhone?
At the moment it looks like that:
In my PopoverView-ViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.hidden = NO;
self.navigationController.navigationBarHidden = NO;
self.navigationItem.title = #"self.navigationItem.title";
}
When calling Popover:
InfoView *iv = [[InfoView alloc] initWithNibName:#"InfoView" bundle:nil];
UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];
self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];
It should look like this:
At first UINavigationController doesn't have own background, it shows background of content view controller. If you can show popover with navigation controller successfully, then check your InfoView. Does it's view has some background?
Second, I tried to execute your code multiple times in different configurations on iPhone, but always have received error
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UIPopoverController
initWithContentViewController:] called when not running under
UIUserInterfaceIdiomPad.
And that was not surprise for me. Even if you could make it work, then Apple may reject your application.
2.1 Apps that crash will be rejected - Just test your code on several devices and see result.
your code
InfoView *iv = [[InfoView alloc] initWithNibName:#"InfoView" bundle:nil];
UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];
self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];
is perfect just hide the default navigation controller and add a navigationBar in the XIB of InfoView.xib and write the cancelButtonAction there to perform the dismissal of the view or the detail of the tableview selection. It Works fine, Please check the image i have done the same way, and believe me it works fine.
Add this to your code before the line [self.pop presentPopoverFromBarButtonItem:se..:
uc.modalPresentationStyle = UIModalPresentationCurrentContext;
See the documentation for the modalPresentationStyle property.
I think you'll need to paste in more of the code for your InfoView controller, as I suspect that's where the problem is.
Have you tried setting up your background view as a class?
[pop setPopoverBackgroundViewClass:bgView];

Single tab in UITabBar does not contain a UINavigationBar

I'm having a really strange issue. I've written an app with five tabs in a UITabBar. When I set the TabBarController's viewControllers property, I set it with five UINavigationControllers, so that each tab will have a UINavigationController within it.
Four of the tabs have it working perfectly. The navigation bar is there when I launch and switch to that tab. However, one of the tabs does not contain the UINavigationBar as I expected it to, and I can't understand why, because I initialized it exactly the same way I initialized all the others.
Here's some sample code from the AppDelegate.m file of initializing the individual view controllers:
SpotFilterViewController *spotList = [[SpotFilterViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:spotList];
[tabs addObject:navigationController];
[navigationController release];
[spotList release];
MySpotViewController *mySpot = [[MySpotViewController alloc] initWithSpot:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:mySpot];
[tabs addObject:mySpot];
[navigationController release];
[mySpot release];
Note: navigationController was declared above.
Anyone else run into this problem before? Or anyone have any idea why this might be happening? Any help is much appreciated. Thanks!
The problem is that you are doing this:
[tabs addObject:mySpot];
instead of this:
[tabs addObject:navigationController];

Navigation Bar in View Based App

I am working on a view based app in iphone, i want to show the Navigation bar when it is loaded, i am using [self.navigationController setNavigationBarHidden:NO animated:YES]; in viewdidload function, but it is still showing the same simple view without the navigation bar at the top, what's the problem
if you are using Xcode4 then do this in app delegate.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
UINavigationController *navcontrol = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navcontrol;
You need to add the NavigationBar to your view.
calling this should sort it out
[self.view addSubview:navigationController.view];

Three20 TTLauncher Issues

So, I'm having some issues with my implementation of the Three20 TTLauncherView. I am using their code, not a fork (although I have heard of rodmaz's version), and I can't get it to work properly. This is what my app looks like.
alt text http://img709.imageshack.us/img709/8792/screenshot20100715at409.png
I removed the icon image, that's not the issue. The issue is, at the top there is no Navigation bar at all, and I believe also causes the white strip at the bottom, which appears to have the same dimensions as a Nav Bar. I've spent quite a while looking through their code and can't figure this out at all. It looks like their Navigation bar (as seen in their Catalog example app) stems from the TTTableViewController, or something further up. However, my app starts like the Facebook app does, not into a table, but into the TTLauncherView. So... how do I get the Navigation bar into my TTLauncher view, if it goes "App Delegate -> TTLauncherView Subclass"
Thanks for your help!
Edit:
Added the code I used. I put this in my app delegate, wrapping my first view with the UINavigation Controller, and it worked just as I wanted!
MainViewController *aController = [[MainViewController alloc] initWithNibName:nil bundle:nil]; //my Main view
self.mainViewController = aController;
[aController release]; //release for Memory Management
self.mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
UINavigationController *navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:self.mainViewController animated:NO]; //Gets the main view on the screen
[window addSubview:navigationController.view];
You simply wrap the view with a navigation bar before you push the new view. As an example, here is a snippet of my code where I present a modal view controller with a navigation bar.
- (IBAction) showNewNavView: (id) sender
{
// Present it as a modal view and wrap the controller in a navigation controller to provide a navigation bar for the Edit and Save buttons
ModalViewController *addController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
addController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[addController release];
}
If you want to add any buttons or set the title of it, you need to do that in the viewDidLoad method of the view that you are pushing (i.e. your TTLauncher view)