I am trying to make a navigation based application having three UIViewController in navigation stack. I have a bottom bar (UITabBar).
I want to hide tabbar when first UIViewController is pushed into the stack and I want to show tabbar when second UIVIewController is pushed.
Here is the code I have written to do so.
For First UIVIewController:
NotificationDetailsVC *obj = [[NotificationDetailsVC alloc] init];
obj.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:obj animated:YES];
[obj release];
For Second UIViewController I have done:
NotificationBO *obj=[self.notificationsArray objectAtIndex:indexPath.row];
object.hidesBottomBarWhenPushed = NO;
[self.navigationController pushViewController:object animated:YES];
[object release];
Now the problem is that, I can get UITabBar Hidden for first UIViewController, but for second it is also hidden.
How can I solve this issue?
Instead of using hidesBottomBarWhenPushed method. Try your code for hiding tabbar in your ViewController, like
[self.tabBarController.tabBar setHidden:YES];
and for showing tabbar
[self.tabBarController.tabBar setHidden:NO];
The above one will work, but the problem is it'll leave an empty space in viewController bottom. To overcome this, set frame to your tabbarController.
For Hiding, set
[self.tabBarController.tabBar setFrame:CGRectMake(0, 480, 320, 50)]
For Showing, set
[self.tabBarController.tabBar setFrame:CGRectMake(0, 430, 320, 50)]
Related
I have a class, DisplayOptViewController, which is a subclass of UICollectionViewController.
I want to display this CollectionViewController when the user clicks a button in the Navigation Bar on my current page. I am able to load the CollectionView on button Click but the Navigation Bar is not coming. I want the user to be able to see a back button in the navigation Bar and clicking the button should take him back to the current page.
I tried to do this via storyboard as well as programmatically. When I try this via the Storyboard, the ViewController itself is not displayed and when I create the view controller object programmatically, I am not getting the Navigation Bar. Any idea how to to this?
I tried to add this code to my viewDidLoad method in DisplayOptViewController:
UINavigationBar *navBar=[[UINavigationBar alloc] init];
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[self.navigationController.navigationBar addSubview:navBar];
But the Navigation Bar still didn't come. Kindly help.
update
I am loading the UICollectionView here
UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init];
[aFlowLayout setItemSize:CGSizeMake(140, 50)];
[aFlowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
DisplayOptViewController *vc=[[DisplayOptViewController alloc] initWithCollectionViewLayout:aFlowLayout];
[self presentViewController:vc animated:YES completion:nil];
You have a few things that i question,
[self.navigationController.navigationBar addSubview:navBar];
you are adding a navigation bar to a navigation bar.... do this instead
[self.navigationController setNavigationBar:navBar];
second
[self presentViewController:vc animated:YES completion:nil];
you are presenting the controller.... not pushing/poping it....
[self.navigationController pushViewController:vc animated:YES];
try that in when you do it programmatically
as for the storyboard maybe you don't have the segues set up correctly, or properties not set right or something... but i can't debug it like this
If you have a navigation based project, then you have to initialize the navigation controller in the app delegate itself. Try the code below to make the navigation bar visible,
In application didFinishLaunchingWithOptions method,
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[self viewController]];
[[self window] setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
Now your navigation bar will appear.
UIToolbar button on the MainViewController presents UIViewController, now i want to display multiple UIViewControllers one after the other via this button.What is the best way to do this.
- (void)displayviewsAction:(id)sender
{
PageOneViewController *viewController = [[[PageOneViewController alloc] init]autorelease];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
}
when button is pressed it displays this UIViewController now right after this UIViewController i want to present multiple UIViewControllers one after the other.
Any ideas please.
Say you want to display view controllers A,B,C by tapping on main view controller's tool bar button. To do so write
[self presentModalViewController:a animated:YES];
on button action. In A's viewDidAppear: method, write
[self presentModalViewController:b animated:YES];
Writing same for all view controllers will display viewControllers one after another.
I've got a fullscreen view inside of a UINavigationController. When I attempt to present a modal view on top of it, the UINavigationBar changes to opaque, pushing down the content, before the modal view animates. How do I keep this from happening?
ContextMenuViewController *cmvc =
[[ContextMenuViewController alloc] initWithNibName:nil bundle:nil];
[cmvc setDelegate:self];
UINavigationController *navControl =
[[UINavigationController alloc] initWithRootViewController:cmvc];
[cmvc release];
[navControl.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self.navigationController presentModalViewController:navControl animated:YES];
[navControl release];
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleBlackTranslucent
animated:NO];
The UINavigationController's root view does not have any transparency (status bar nor UINavigationBar), only the pushed controllers have the transparency.
I created a video of the issue: http://www.youtube.com/watch?v=KSFvzTR5Ejk
Example source at: http://cl.ly/7lu2
I tried your code in a very small test project and didn't see the issue you describe. I suggest you do the same thing. Start with the Navigation-based Application template. In the main nib, check the navigation controller's Wants Full Screen and Resize View From Nib, and make its nav bar transparent. In the root view controller's nib, put a button that you can respond to, set up the action, and paste in your code. Create the ContextMenuViewController class; there is no need to give it a nib.
Run the app and press the button. The modal view slides into place, with a transparent nav bar, without affecting the transparency of the nav bar that already exists and without moving the existing content.
So now, once you've proved to yourself that it works in this simple project, it's just a question of locating what you're doing different from that in the real project.
Try setting the bar styles during viewDidLoad for the root View Controller.
HERE YOU GO )
OptionsViewController *detailViewController = [[OptionsViewController
alloc] initWithNibName:#"OptionsViewController" bundle:nil];
UINavigationController *optionsController = [[UINavigationController
alloc] initWithRootViewController:detailViewController];
[detailViewController release];
optionsController.navigationBar.translucent = YES;
optionsController.navigationBar.opaque = YES;
optionsController.navigationBar.tintColor = [UIColor clearColor];
optionsController.navigationBar.backgroundColor = [UIColor
clearColor];
optionsController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:optionsController animated:YES];
[optionsController release];
I'm using a Navigation Controller. My RootViewController pushes a number of views but it also presents a modal view. That modal view presents a tableView. So what I'm trying to do is figure out of I can push the Navigation Controller across the modal view, then use it from that modal view to push the view with the tableView? or barring that, is there a way to implement a second Navigation Controller from the modal view?
The real issue is that I want to present the view with the tableView using a right to left transition, which of course is not available with modal views.
I have this code that SORT OF provides the right to left transition used by the Navigation Controller:
NewViewController *newViewController = [[NewViewController alloc] init];
[self presentModalViewController:newViewController animated:NO];
CGSize theSize = CGSizeMake(320, 460);
newViewController.view.frame = CGRectMake(0 + theSize.width, 0 + 20, theSize.width, theSize.height);
[UIView beginAnimations:#"animationID" context:NULL];
[UIView setAnimationDuration:0.5];
newViewController.view.frame = CGRectMake(0, 0 + 20, 320, 460);
[UIView commitAnimations];
[newViewController release];
The problem is that the OldViewController (the one calling the NewViewController) disappears immediately so the NewViewController transitions across a blank screen, instead of covering the OldViewController.
Presenting a UIViewController modally creates a whole new navigation stack. You could do something like this:
//Create the view you want to present modally
UIViewController *modalView = [[UIViewController alloc] init];
//Create a new navigation stack and use it as the new RootViewController for it
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:modalView];
//Present the new navigation stack modally
[self presentModalViewController:nav animated:YES];
//Release
[modalView release];
[nav release];
This can be done because UINavigationController is a subclass of UIViewController. When the new view is loaded, you can use it however you wish (push another view on top of it, us UIView animations like Waqas suggeste, etc').
I hope I got your question correctly. Do tell if I didn't.
I have app with UItabBarTemplate with navigation controller.
On selecting tab bar ViewControllerA is shown which on button touch pushes UIPieChartTabController which inherits "UIViewController".
Now I want another tab bar in UIPieChartTabController.
so in viewDidLoad of UIPieChartTabController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
UITabBarController *tabbar= [[UITabBarController alloc] init];
tabbar.view.frame = CGRectMake(0, 0, 320, 460);
piechartViewController *pr=[[piechartViewController alloc]init];
pr.tagInAction=1;
pr.title=#"Type";
pr.tabBarItem.image=[UIImage imageNamed:#"trend.png"];
pr.sDate=sDate;
pr.nDate=nDate;
piechartViewController *pr1=[[piechartViewController alloc]init];
pr1.title=#"category";
pr1.tagInAction=4;
pr1.sDate=sDate;
pr1.nDate=nDate;
piechartViewController *pr2=[[piechartViewController alloc]init];
pr2.title=#"paidWith";
pr2.tagInAction=3;
pr2.sDate=sDate;
pr2.nDate=nDate;
//tabbar.tabBar.delegate=self;
//this gave me error
ExportRep *pr3=[[ExportRep alloc]init];
pr3.tabBarItem.image=[UIImage imageNamed:#"database.png"];
pr3.title=#"Export Expenses";
[tabbar setViewControllers:[NSArray arrayWithObjects:pr,pr1,pr2,pr3,nil]];
[self.view addSubview:tabbar.view];
[pr release];
[pr1 release];
[pr2 release];
}
This piece of code worked but now when I select tab of viewController ExportRep type I tried
[self presentModalViewController:objMFMailComposeViewController animated:YES];
but navigationController of objMFMailComposeViewController hides behind navigationController of view that is presenting objMFMailComposeViewController.
Also viewWillAppear viewDidAppear of all the view controller which are bound to tab bar never gets called.
But none of this problem occurs for tabbar and viewcontroller which gets created by UITabbarTemplate.
Why Is it so? Whats wrong when I create Tab bar?
placing another tabBar within a tabbarVC, is not recommended. Why not use a UIToolBar to do the swapping of Views in your PieChartVC instead?
-apart from that, the reason your code doesn't call viewWillAppear,viewDidAppear is because of this:
[tabbar setViewControllers:[NSArray arrayWithObjects:pr,pr1,pr2,pr3,nil]];
[self.view addSubview:tabbar.view];
here only loadView of those prs will be called.
the viewControllers you assign to the tabBars should instead be wrapped around UINavigationControllers.
So something like this instead would do the trick
UINavigationController *nc1 = [[UINavigationController alloc]initWithRootViewController:pr];
[nc1.view setFrame:CGRectMake:("the frame in which you wnt prs to be displayed")];
[pr.view setFrame:nc1.view.frame];
. // similarly assign NavControllers for all prs
.
.
.
[tabbar setViewControllers:[NSArray arrayWithObjects:nc,nc1,nc2,nc3,nil]];
[self.view addSubview:tabbar.view];
The reason why new view which is being presented modally got its navigation bar hidden lies in [self.view addSubview:tabbar.view];
so it got room to present its view only in parent controllers view thus got cut its navigation bar.
so to hack it I kept tab selected and instead of presenting it in selected view controller,have presented it in main view controller only.