- (void)cancel {
// What should I do here?
}
// root view controller
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(cancel)];
self.navigationItem.leftBarButtonItem = cancelButton;
[cancelButton release];
}
I added cancel button in the navigation bar.
I want to go back to the previous view from root view when cancel button is pressed.
What do I have to do in cancel? I added root view controller like this.
RootController *rootController = [[RootController alloc]initWithStyle:UITableViewStylePlain];
UINavigationController *aNavigationController = [[UINavigationController alloc]initWithRootViewController:rootController];
self.naviController = aNavigationController;
[aNavigationController release];
[rootController release];
[self.view addSubview:[naviController view]];
You can pop the view.
[self.navigationController popViewControllerAnimated:YES];
You can dismiss it as well.
dismissModalViewcontrollerAnimated
EDIT:
If you are adding the view then you need to remove your view.
[self.view removeFromSuperView];
If you used a navigationController to push the view you can make use of popViewController: animated: method. If you presented the view as a modal view you can make use of dismissModalViewcontrollerAnimated: method
It seems you are not pushing or presenting the aNavigationController. You are just adding it as a subview. Neither popViewController nor dismissModalViewController won't work here. You have to just remove it from its superView. Try this.
- (void)cancel {
[self.view removeFromSuperView];
}
Add This.
[self.view removeFromSuperview]
Related
I have an app that based on Tab Bar combined with navigation bar.
In the navigation bar i have a button that takes me to another page which I want to hide the tab bar. When i trying to back to the main view through a button (Not back bar button, regular one) i can't bring the Tab Bar back.
I did try : xxxxx.hidesBottomBarWhenPushed =NO;
Here is some of my code:
In main view:
In viewDidLoad:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:buttonTitle
style:UIBarButtonItemStylePlain
target:self
action:#selector(goToCreateEvent)];
-(void)goToCreateEvent{
UIViewController *targetViewController;
NSString *viewControllerName = #"CreateAnEventViewController";
targetViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil];
targetViewController.hidesBottomBarWhenPushed =YES; //Hides the tab bar
[self.navigationController pushViewController:targetViewController animated:YES];
}
In the other view:
-(IBAction)save:(id)sender
{
[summary resignFirstResponder];
[agenda resignFirstResponder];
FeedViewController *aboutViewCont = [[FeedViewController alloc] init];
aboutViewCont.hidesBottomBarWhenPushed =NO; //trying to bring back the tab bar
[[self navigationController] pushViewController:aboutViewCont animated:NO];
}
Thanks!
Yossi
This simply solve it:
[[self navigationController] popToRootViewControllerAnimated:YES];
in viewWillAppear: method of FeedViewController set hidesBottomBarWhenPushed to NO like bellow..
-(void)viewWillAppear:(BOOL)animated{
self.hidesBottomBarWhenPushed = NO;
}
UPDATE: Try out this one also..
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
CGRect r = self.tabBarController.view.frame;
r.size.height +=self.tabBarController.tabbar.frame.size.height;
self.tabBarController.view.frame = r;
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.tabBarController.view.frame = CGRectMake(0, 0, 320, 480); //for iPhone portrait
}
use this above methods in your FeedViewController class and also just comment this bellow line from your code..
targetViewController.hidesBottomBarWhenPushed =YES;//comment this..
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.
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];
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];