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..
Related
I want to dismiss my navigation bar image(not the background image).That is i have set navigation bar image on the left side . when i go to the next controller the image overlaps the back button . This is my home screen with image in blue marked .
And this my second screen With image overlaped
And this the code i used to set the image in the bar
UINavigationBar *bar = [self.navigationController navigationBar];
UIImageView *barImg=[[UIImageView alloc]initWithFrame:CGRectMake(2, 3, 49, 39)];
barImg.image=[UIImage imageNamed:#"smalllogo.png"];
[bar addSubview:barImg];
[barImg release];
Now i dont want the image in my other screens what can i do for that?
One thing you can do is Add your image in side the viewWillAppear: method and remove it from the navigation bar when viewWillDisappear: method. Related code block as follows.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UINavigationBar *bar = [self.navigationController navigationBar];
UIImageView *barImg=[[UIImageView alloc]initWithFrame:CGRectMake(2, 3, 49, 39)];
barImg.image=[UIImage imageNamed:#"smalllogo.png"];
barImg.tag = 100;
[bar addSubview:barImg];
[barImg release];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
UINavigationBar *bar = [self.navigationController navigationBar];
[[bar viewWithTag:100] removeFromSuperview];
}
Or Here's another simple solution. Add below code segment to viewWillAppear: method
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"smalllogo.png"]]];
[self.navigationItem setLeftBarButtonItem:item];
[item release];
You have added the image in the navigation bar but not removed it before moving into other view.
Use `
-(void)viewWillDisappear:(BOOL)animated{
[barImg removeFromSuperview];
}`
to remove it from superview.
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 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];
I would like to implement a search bar with the exact same behavior as the mail app on the iphone. I cannot get the scopebar to reveal itself smoothly while the navigation bar and search bar are shifting upwards the way the mail program does it. In the mail app the nav bar and search bar move up to reveal the scopebar. How would i implement that kind of animation?
I did something crude:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:#"Button",#"Titles",#"Go",#"Here",nil];
searchBar.showsScopeBar = YES;
[searchBar setShowsCancelButton:YES animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];
self.tableView.contentOffset = CGPointMake(0, 0);
[searchBar sizeToFit];
return YES;
}
the search bar is allocated in my viewdidload as follows:
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchBar.delegate = self;
self.tableView.tableHeaderView =searchBar;
[searchBar release];
In my viewwillappear i offset the table view to hide the search bar under the nav bar:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableView.contentOffset = CGPointMake(0, 44);
}
Thanks!
Try sending -setNavigationBarHidden:animated: to the navigation bar in - searchBarTextDidBeginEditing:.
In my app I have a basic Navigation Controller. For all of my views, except one, the controller works as it should.
However, for one view in particular, I would like the 'back' button to not go back to the previous view, but to go to one I set. In particular it is going to go back 2 views and skip over one.
After doing some research I found that I can intercept the view when it disappears, so I tried to put in code to have it navigate to the page I would like:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//i set a flag to know that the back button was pressed
if (viewPushed) {
viewPushed = NO;
} else {
// Here, you know that back button was pressed
mainMenu *mainViewController = [[mainMenu alloc] initWithNibName:#"mainMenu" bundle:nil];
[self.navigationController pushViewController:mainViewController animated:YES];
[mainViewController release];
}
}
That didn't work, so does anyone have any ideas?
Thanks!!
In your code, you seem to be trying to push another view controller onto the stack, rather than pop an extra item off it.
Try this as your code that does the going back two levels:
NSArray *vcs = [self.navigationController viewControllers];
[self.navigationController popToViewController:[vcs objectAtIndex:[vcs count]-3];
Alternatively you could totally replace the back button with a button of your own? In your viewController:
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:#selector(doSomething:)];
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = item;
[item release];
Then you can write the doSomething: method to pop the two items off the stack, perhaps using the code I posted above.
Simple solution:
- (void)viewWillDisappear:(BOOL)animated {
//if true, back was pressed
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
//your logic
}
}
You can try implementing the UINavigationBarDelegate delegate. When the method -navigationBar:didPopItem: is called, you can pop an additional item from the UINavigationController, and thus pop two items at once.
UIButton *home = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *homeImage = [UIImage imageNamed:#"back.png"];
[home setBackgroundImage:homeImage forState:UIControlStateNormal];
[home addTarget:self action:#selector(LogOut)
forControlEvents:UIControlEventTouchUpInside];
home.frame = CGRectMake(0, 0, 69, 26);
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:home];
[[self navigationItem] setLeftBarButtonItem:button2];
[button2 release];
button2 = nil;