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.
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.
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)]
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];
So, I'm having some issues with my implementation of the Three20 TTLauncherView. I am using their code, not a fork (although I have heard of rodmaz's version), and I can't get it to work properly. This is what my app looks like.
alt text http://img709.imageshack.us/img709/8792/screenshot20100715at409.png
I removed the icon image, that's not the issue. The issue is, at the top there is no Navigation bar at all, and I believe also causes the white strip at the bottom, which appears to have the same dimensions as a Nav Bar. I've spent quite a while looking through their code and can't figure this out at all. It looks like their Navigation bar (as seen in their Catalog example app) stems from the TTTableViewController, or something further up. However, my app starts like the Facebook app does, not into a table, but into the TTLauncherView. So... how do I get the Navigation bar into my TTLauncher view, if it goes "App Delegate -> TTLauncherView Subclass"
Thanks for your help!
Edit:
Added the code I used. I put this in my app delegate, wrapping my first view with the UINavigation Controller, and it worked just as I wanted!
MainViewController *aController = [[MainViewController alloc] initWithNibName:nil bundle:nil]; //my Main view
self.mainViewController = aController;
[aController release]; //release for Memory Management
self.mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
UINavigationController *navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:self.mainViewController animated:NO]; //Gets the main view on the screen
[window addSubview:navigationController.view];
You simply wrap the view with a navigation bar before you push the new view. As an example, here is a snippet of my code where I present a modal view controller with a navigation bar.
- (IBAction) showNewNavView: (id) sender
{
// Present it as a modal view and wrap the controller in a navigation controller to provide a navigation bar for the Edit and Save buttons
ModalViewController *addController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
addController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[addController release];
}
If you want to add any buttons or set the title of it, you need to do that in the viewDidLoad method of the view that you are pushing (i.e. your TTLauncher view)
I'm writing a custom UITabBarController so I can fully control appearance of the tab bar. I've got it all working so I have an array of view controllers that it handles.
The controller has a main view which fills the screen, and inside it it has a UIView at the bottom for the tab bar. That tab bar view has a button for each view controller. When buttons are pressed I add the view controller's view to the main view, and set it's frame so that it doesn't cover the tab bar view:
controller.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - kTabBarHeight);
This all works fine, and I can flick between the view controllers just fine. However, when I present a modal view controller, and then dismiss it, the current view controller's view becomes full screen and covers up my tab bar! I've tried setting the autoresizing masks to not resize, but is keeps happening.
I have also tried adding the view controllers view's to the bottom (below the tab bar) by using:
[self.view insertSubview:controller.view atIndex:0];
But when I do that, the tab bar is even visible above any modal views! Which is strange. I think there's something I'm not understanding so I would be grateful if someone can explain what I'm missing!
Thanks,
Mike
Try setting
controller.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - kTabBarHeight);
in the controller's viewWillAppear method
Try this out. I think you want dynamic view controllers within tab bar controller.
-(void)applicationDidFinishLaunching:(UIApplication *)application {
// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate=self;
tabBarController=[[UITabBarController alloc] init];
mainDashBoard=[[DashBoard alloc] initWithNibName:#"DashBoard" bundle:nil];
mainSearchView=[[SearchView alloc] initWithNibName:#"SearchView" bundle:nil];
mainMoreView=[[MoreView alloc] initWithNibName:#"MoreView" bundle:nil];
UINavigationController *nvCtr0=[[[UINavigationController alloc] init] autorelease];
UINavigationController *nvCtr1=[[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
UINavigationController *nvCtr2=[[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
UINavigationController *nvCtr3=[[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
UINavigationController *nvCtr4=[[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];
tabBarController.viewControllers=[NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];
nvCtr0.tabBarItem.enabled=NO;
nvCtr4.tabBarItem.enabled=NO;
[window tabBarController.view];
}
I've managed to find a better way to control the appearance of the tab bar by simply inserting subviews to the top of the tab controllers tab bar. It's worked a treat!