I have a fullscreen modalView called like this:
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:#"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
[self presentModalViewController:navController animated:YES];
Then from this modalView I push another view :
MyController *nextWindow = [[[MyController alloc] initWithNibName:#"tmp" bundle:nil] autorelease];
[self.navigationController pushViewController:nextWindow animated:YES];
In this new controller, I have this viewDidLoad :
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Borders";
self.navigationController.navigationBarHidden = NO;
}
The leftBarButtonItem is not active, I mean touching it does not highlight it nor does it go back to the previous view.
My views are displayed fullScreen, with [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; called at the application initialisation.
The navigationBar frame is 0,0,320,44.
The navigationBar superview frame is 0,0,320,480.
The viewController view frame is 0,0,320,436.
I've tried to call in viewDidLoad self.navigationController.navigationBar.userInteractionEnabled = YES; and self.navigationItem.leftBarButtonItem.enabled = YES; without effect.
What happens?
EDIT :
My self.navigationController.navigationItem.backBarButtonItem is NIL.
self.navigationController.navigationItem is not NIL
Whenever this sort of unresponsiveness happens to me, it is always because of framing issues. i.e. the superview of the NavigationController is smaller than the NavigationController's view. I know you say that everything is set to full screen, but I would verify that everything is actually full screen by turning "clipsSubviews" on for each view in the hierarchy.
I just had this issue, I'm not sure why this works, but instead of doing:
UIBarButtonItem *backButton =
[[[UIBarButtonItem alloc] initWithTitle:#"Back"
style: UIBarButtonItemStyleBordered
target:nil
action:nil] autorelease];
self.navigationItem.leftBarButtonItem = backButton;
I replaced the second line with
self.navigationController.navigationItem.leftBarButtonItem = backButton;
That works for me.
I found the solution.
The problem was that the first view was called from the overlay, and not from the picker.
Keeping a reference to the Picker into the overlay, and calling the view from it solves the problem:
From the overlay:
[self.picker presentModalViewController:navController animated:YES];
works
instead of:
[self presentModalViewController:navController animated:YES];
Related
I am trying to present a modal view from one of my view. The presenter view is already shown as a modal from a custom view. My problem is that I am not able to see the 'Done' button on the new Modal view presented. Below is my code. Am I missing something?
UIViewController *aViewController = [[UIViewController alloc] init];
UINavigationController *aNavigationController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
[aNavigationController.navigationBar setBarStyle:UIBarStyleBlack];
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissMe)];
[aNavigationController.navigationItem setLeftBarButtonItem:aBarButtonItem];
MyView *aView = [[MyView alloc] initWithFrame:self.view.frame];
[aViewController.view addSubview:aView];
[self presentModalViewController:aNavigationController animated:YES];
[aViewController release];
- (void)dismissMe {
[self dismissModalViewControllerAnimated:YES];
}
If I understand weel the question, you can try a solution like this:
Write this in the viewDidLoad or init method of the modal view controller you want to show from the actual view:
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self selector:#selector(dismissMe)];
self.navigationController.leftBarButtonItem = done;
and implement you dismissMe method.
Instead, in the presenter controller write this where you want to present the new modal controller:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controllerYouWantToShow];
[self presentModalViewController:navController animated:YES];
Obviusly, controllerYouWantToShow is a pointer/variable pointing your view controller you want to show... I usually do this to solve a problem like yours... However, check the code because I havent't tested it :)
Hope it helps!
I'd like to add a UINavigationController to my app info view (NOT to my main view). I've watched/read a number of tutorials showing how to add it to the main window through the AppDelegate using IB. In my case, I only want it to appear when a user presses the info button and is brought to the infoView. Here is how I switch to the infoView within my MainViewController:
- (IBAction)infoButtonPress:(id)sender
{
// Create pointer to instance of InfoViewController
InfoViewController *infoView = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
// Add view switching animation
infoView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// Change view using animation
[self presentModalViewController:infoView animated:YES];
}
At this point the infoView is displayed and I would like THIS to be the RootView of the UINavigationController. I have tried adding the line:
UINavigationController *infoNavController = [[UINavigationController alloc]
initWithRootViewController:infoView];
after creating an instance of InfoViewController, but the app crashes. Is it possible to add UINavigationController to views other than the main view?
Thanks.
You are very close with your implementation. Try it in this order.
InfoViewController *infoView = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
UINavigationController *infoNavController = [[UINavigationController alloc]
initWithRootViewController:infoView];
[infoView release]; // skip this if using ARC
infoView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:infoNavController animated:YES];
UPDATE
To kill this modal, you will have to add your buttons to the main modal view.
InfoViewController.m
-(void)cancel:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
-(void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *cancelButton =
[[UIBarButtonItem alloc] initWithTitle: #"Cancel"
style: UIBarButtonItemStylePlain
target: self
action: #selector(cancel:)];
self.navigationItem.leftBarButtonItem = cancelButton;
[cancelButton release];
}
see the screen shot is clear to understand what I mean
you can see I add a navigationItem in my pop view
I wish I can dismiss the pop view
But it seems only tab the cell under the pop view
The pop view will dismiss,I try to add this method
[self.view removeFromSuperview];
It only remove the table view , the pop view frame is still there ,only without the content view
Any reply will be helpful : )
Thanks
Webber
/******EDIT******/
I use WEPopoverView into my project
And this is the code I create the pop view when I select the table view
if (indexPath.row==2) {
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
if (self.popoverController) {
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
else {
self.popoverController = [[[WEPopoverController alloc] initWithContentViewController:navPopView] autorelease];
CGRect frame = [tableView cellForRowAtIndexPath:indexPath].frame;
[self.popoverController presentPopoverFromRect:frame
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
animated:YES];
}
}
/******EDIT2******/
I try to add Done button when I create the pop view
here is the code , But it only appear a navigation , no Done button
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
navPopView.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(hidePopView)];
While you add the popup view, set tag to that popupView and then, add them as subview,
then use:
for (UIView *tempView in [self.view subviews]) {
if ([tempView tag]==urTag) {
[tempView removeFromSuperview];
}
}
This retrieves all the subviews and then remove only your popupview
I think that simply releasing your self.popoverController will do the dismiss properly, including all the superviews.
You can also have a look at the dealloc method in WEPopoverController to see which views are involved and need to be removed:
[self dismissPopoverAnimated:NO];
[contentViewController release];
[containerViewProperties release];
[passthroughViews release];
Anyway, the only advantage I see is the possibility of calling dismissPopoverAnimated with YES.
Hope this helps.
EDIT:
How can you connect your done button to your controller?
Make your button accessible through a read-only property of DaysOfWeek; then in your controller, when you create DaysOfWeek, do:
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
[propView.doneButton addTarget:self action:#selector(fullyDismissPopover) forControlEvents:UIControlEventTouchUpInside];
In fullyDismissPopover, you call release or call the sequence of functions highlighted above (but release would be better, I think).
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[doneButton addTarget:self action:#selector(hidePopView) forControlEvents:UIControlEventTouchUpInside];
popView.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:doneButton] autorelease];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
This also can figure out the problem !
I am facing an issues with navigating between the views, Basically I have 3 views:
RootView
view1
View2
What I want to do is when I click on back button of View2 I want RootView to be loaded instead of loading view1 (which is default).
.. I have written the below code in My view1.m before pushing the view2ViewController, code:
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:#"Back" target:self action:#selector(someMethod:)];
self.navigationItem.backBarButtonItem = back;
-(void)someMethod:(id)sender{ [self.navigationViewCOntroller popToRootViewControllerAnimated:YES] }
The above code is not working
Try this:
To go to a View:
Aview *aview =[[Aview alloc] initWithNibName:nil bundle:nil];
settings.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:settings animated:YES];
To go back:
[self dismissModalViewControllerAnimated:YES];
So in ur case its:
-(void)someMethod:(id)sender{
Rootview *rootview =[[Rootview alloc] initWithNibName:nil bundle:nil];
settings.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:settings animated:YES];
}
The second half of your question is not clear.
Try this
[self.navigationController popToRootViewControllerAnimated:YES];
Hope this will work for you. By this you can navigate from View2 to your root view.
Check this, im pushing a modal view inside of another modal view. But, im trying to put a button inside of this modal view, but without luck.
What im doing wrong?
Thanks!
CadastroViewController *addController = [[CadastroViewController alloc] initWithNibName:#"CadastroViewController" bundle:nil];
// This is where you wrap the view up nicely in a navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
// You can even set the style of stuff before you show it
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleBordered target:self action:#selector(buy)];
// And now you want to present the view in a modal fashion all nice and animated
[self presentModalViewController:navigationController animated:YES];
// make sure you release your stuff
[navigationController release];
[addController release];
You'll have to add a new UINavigationItem to the navigationbar of the actual viewcontroller - NOT the navigation controller.
addController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleBordered target:self action:#selector(buy)];
You should add your button in a
-(void) viewDidLoad of your CadastroViewController controller class
This will look like this:
- (void) viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleBordered target:self action:#selector(buy)];
self.navigationController. leftBarButtonItem = button;
[button release];
}
[self presentModalViewController: navigationController animated:YES]; is ok in your example, just all other initializations you should do in viewDidLoad
It seems to me, that the problem is here:
[self presentModalViewController: navigationController animated:YES];
Instead try do this:
[self presentModalViewController: addController animated:YES];