NavigationController done button is not showing - iphone

When i press the infobutton on the mainviewcontroller it shows navbar and uitextview modally but doesn't shows done button.
- (void) modalViewAction:(id)sender
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
navigationController.navigationBar.tintColor = [UIColor brownColor];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(Done:)] autorelease];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[navigationController release];
Anyone have ideas why is that Done Button is missing from the navigationcontroller.
Thanks for help.

Your presenting it Modally:
[self.navigationController presentModalViewController:self.viewController animated:YES];
You need to push it onto the navigation stack:
[self.navigationController pushViewControler:self.viewController animated:YES];
Now the NavigationController will take care of the back button for you.

You have to either:
push the view controller onto the navigation controller (as Hubert
explained), or
create a new UINavigationController and set the
viewController as the rootViewController of that
UINavigationController and then you can do:
[self.navigationController
presentModalViewController:newNavigationController animated:YES];

I added following statement
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
to the below code and now Done button is showing on the navigation controller
- (void) modalViewAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[self.view addSubview:navigationController.view];
[navigationController release];
}
So my issue is solved.
Thanks for help

Related

How to add UINavigationBar in an UIViewController?

I have an UIViewController class(Say it is XXX). I present this view controller as modally by the code..
XXX *xxx = [ [XXX alloc] init];
[self presentModalViewController:xxx animated:YES];
[xxx release];
I want to add a navigation bar on the top of the XXX view. So I used UINavigationBar object in XXX's loadView method.
UINavigationBar *navBar = [ [UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:navBar];
[navBar release];
But, It throws an error as "EXC_BAD_ACCESS". Any help...?
Thanks
OPTION-1:
Try adding navigation bar from the XIB of viewController called XXX.
OPTION-2:
Add a UINavigationController and present it modally.
Replace your code :
XXX *xxx = [[XXX alloc] init];
[self presentModalViewController:xxx animated:YES];
[xxx release];
with this code:
XXX *xxx = [[XXX alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:xxx];
[self presentModalViewController:navigation animated:YES];
[navigation release];
Hope this helps you.
Replace your code with:
XXX *xxx = [[ [XXX alloc] init]autorelease];
[self presentModalViewController:xxx animated:YES];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:xxx];
[self presentModalViewController:navigation animated:YES];
[navigation release];
I think it will solve your "EXC_BAD_ACCESS" problem.
you can try this by adding toolbar at the top of the view. In many cases i have seen for poping MODAL controller this is nice solution. but if you want to navigate more controllers from MODAL controller then you should use UINavigationController.
you do it like this:
XXX *xxx = [[XXX alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:xxx];
[self presentModalViewController:navigationController animated:YES];
[xxx release];
[navigationController release];

Transitionstyle of UIViewController presented modally

I am using the below statement to define the transitionstyle
_viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
in the below code but the above statement is not flipping horizontally while presenting it modally
#property (nonatomic, assign) UIModalTransitionStyle *modalTransitionStyle;
#synthesize modalTransitionStyle;
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
_viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:_viewController animated:YES];
Anyone knows that why it is so. When everthing is coded programmtically.
Thanks for help though.
There's a lot of confusing naming going on here.
AFAICT, _viewController is the root view controller of your navigationController. But you reference self.viewController... is this the same view controller? If so, why are you not consistently using accessor methods? If not, it's not clear to me that you setting the modal transition style on the correct view controller ([self viewController] vs. _viewController).
(Btw, please work on formatting your code so that it displays in a more reasonable way when you paste it in.)
Wrong way to approach the problem. I suggest you to review your code in order to improve readability and maintainability.
Supposing that you've a viewcontroller with a target action associated with a button, something like this:
...
[aButton addTarget:self
action:#selector(dismissView:)
forControlEvents:UIControlEventTouchUpInside];
...
You can write a selector method, in order to display your new viewcontroller as follow:
- (void)dismissView:(id)sender {
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:secondVC animated:YES];
[secondVC release];
}

How to flip vertically UIViewController which is presented modally

How can I vertically flip a UIViewController which is presented modally along with a UINavigationController and Done Button.
This is how I am presenting the UIViewController modally:
- (void)modalViewAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds] autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[self.view addSubview:navigationController.view];
[navigationController release];
}
How can I flip this UIViewController whilst presenting it modally?
Thanks for your help.
You can specify the desired animation technique by setting the modalTransitionStyle property (before presenting the view controller).
Unfortunately this property can be set only to:
UIModalTransitionStyleCoverVertical
UIModalTransitionStyleFlipHorizontal
UIModalTransitionStyleCrossDissolve
UIModalTransitionStylePartialCurl
So vertical flip it is not supported.
Take a look at UIModalTransitionStyle reference:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

modalviewcontroller shows gap after loading

Modalviewcontroller is showing gap after loading. Gap is after staus bar which moved modalviewcontroller down and gap shows me main window. So how i can remove this gap which is showing between status bar and modalviewcontroller. There is no interface builder involved. Creating everything programmtically. Help for this will be really appreciated.
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:#selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *infoItem = [[UIBarButtonItem alloc] initWithCustomView:button];
- (void)displayModalViewaction: (id) sender
{
self.viewController = [[Infoviewcontroller alloc] init];
UINavigationController *navigationController=[[UINavigationController alloc] init];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[navigationController pushViewController:_viewController animated:YES];
[self.view addSubview:navigationController.view];
}
Thanks
In your _viewController, you need to update this code if you want to hide the gap -
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
But ideally it needs to be fixed by-
[self presentModalViewController:navigationController animated:YES];
Not sure why it is not working for you.
Assuming this code is in a UIViewController you probably want to do something like this.
self.viewController = [[[Infoviewcontroller alloc] init] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
By adding the view frame size [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; fixed the gap between status bar and modal view.

problem with UIPopoverController while navigation

I have UIPopoverController and two ViewController class.
SaveProject and ProjectName is viewController class.
When i am clicking save project. its give me navigation and load another view.
But the UIPopoverController size height is getting increased to the total view size.
Can any one help me out with this..
I am attaching here code:
-(void)createSaveAndCloseView{
saveAndCloseViewController = [[WGSaveAndCloseViewController alloc]init];
[saveAndCloseViewController.view setFrame:CGRectMake(0, 0, 310, 171)];
saveAndCloseViewController.navigationItem.title = #"Save or Discard";
UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStylePlain target:self action:#selector(cancelAction:)];
saveAndCloseViewController.navigationItem.rightBarButtonItem = cancel;
[cancel release];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:saveAndCloseViewController];
saveAndClosePopupView = [[UIPopoverController alloc] initWithContentViewController:navControl];
saveAndClosePopupView.delegate = self;
saveAndClosePopupView.popoverContentSize = CGSizeMake(312, 160);
saveAndCloseViewController.view.contentMode = UIViewContentModeScaleAspectFill;
[saveAndClosePopupView presentPopoverFromRect:[saveAndClose bounds] inView:saveAndClose permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[navControl release];
}
-(void)saveProjectClick:(id)sender{
if (saveProject.tag == tagSave) {
WGNameProjectViewController *nameProjectViewController = [[WGNameProjectViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:nameProjectViewController animated:YES];
nameProjectViewController.navigationItem.title = #"Name Project";
[nameProjectViewController release];
nameProjectViewController = nil;
}
}
You just need to add something like:
self.preferredContentSize = <view size>
to the viewWillAppear: method in each of your view controllers that are displayed in the popover.