I have usually placed tab bar on its as usual bottom I have used following code in application didFinishLaunchingWithOptions for that.
MemberVC *MemberTabBar = [[MemberVC alloc]init];
UINavigationController *navMember = [[UINavigationController alloc] initWithRootViewController:MemberTabBar];
MemberTabBar.tabBarItem.title = #"Member";
MemberTabBar.tabBarItem.image = [[UIImage imageNamed:#"home_icon.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
MemberTabBar.tabBarItem.selectedImage = [[UIImage imageNamed:#"home_icon.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-----------------------
self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController.viewControllers = #[navMember,navEvent,navPromo,navProfile,navAbout];
self.window.rootViewController = tabBarController;
tabBarController.selectedIndex = 0;
I haver found one source to place it in top but i want to find out the better way.
I have gained some knowledge about how to place in top from following git projects. If any one knows some better way then i will be glad to know about that
https://github.com/hollance/MHTabBarController
How to place tab bar on top of screen in iPhone
You cannot move the TabBar to the top. You'll have to create custom one. Check this article about customizing tab bar:
http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/
Basing on it you may move the custom tab bar to the top and acheive desired result
One way is, you can add UIViewController instead of UITabBarController and add a tabBar to that view controller on the top.
This link may help you.
Related
I have gone through almost all question related to this on Stack Overflow
What I what to do is to show TabBarViewController as in the image.
Is there any way to achieve this in my tab bar view controller app?
NO, there needs to be at least one Tab selected. By default the Tab bar will select the first view controller object.
if you want to use Tabbar more flexible, you can use a customView instead of TabBarViewController's tabor, just like:
UIView *customTabBar = [[UIView alloc] init];
customTabBar.frame = self.tabBar.bounds;
[self.tabBar addSubview:customTabBar];
I am working on a project in which i have to use search bar on tab bar controller on the top. i tried so many codes but not working i am sharing my code. please help me to overcome this problem.
UISearchBar *search = [[UISearchBar alloc] init];
search.frame = CGRectMake(5 ,5, 300,45);
search.delegate = self;
search.showsBookmarkButton = NO;
search.placeholder = #"Search/Select a Creative Service";
search.barTintColor = [UIColor blackColor];
Set your search bar as the title view:
self.navigationItem.titleView = search;
Create one baseviewcontroller and add your UISearchBar in it. After that you can inherit your each tab's ViewController from that baseviewcontroller. So, in each tab of your UITabBarController you will get that UISearchBar.
The code you have written to create a UISearchBar is correct. Just add it to the view of the baseviewcontroller. Also, please ensure that frame is set correctly.
I've been struggling with that too until I tried something and it turned out it's very simple !
All you need to do is to add UISearchBar and a Container View in one UIViewController and then from that Container View set the segue to your UITabBarController and here you go ! One search bar across all the tabs and the solution will also help in separating the logic of the search functionality from the tabs functionality as you will not be forced to implement a search view across all your tabs.
Here I created a view controller with 1 UIView containing a search bar and an account icon and also containing a Container View (The blue part) which will hold out TabBarController
I have a iPhone app in which need to add UISearchbar on navigation bar, so that user can search from any where inside the app. When User Searches it displays search result in a Tableview controller and User can select any row which pushes to other controller.
Below is the Structure which i have in StoryBoard
Navigation Controller
Tab Bar Controller
View Controller1
View Controller2
View Controller3
View Controller4
I can successfully add the UIsearchbar on Navigationbar in ViewController 1
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:SEARCH]];
imageView.frame = CGRectMake(0, 0, 20, 20);
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(searchTapped:)];
[imageView addGestureRecognizer:tapGesture];
self.searchButton = [[UIBarButtonItem alloc] initWithCustomView:imageView];
self.searchButton.style = UIBarButtonItemStylePlain;
self.searchButton.target = self;
[self.searchButton setTintColor:[UIColor whiteColor]];
self.tabBarController.navigationItem.rightBarButtonItem = self.searchButton;
I can successfully implement the Search results as well in Tableview controller but when user select row it Pushes to different controller. Below is the code which implmenetd to push to different controller.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
EntityViewController *entityController = [mainStoryboard instantiateViewControllerWithIdentifier:ENTITYIDENTIFIER];
entityController.dataDic = result;
[self.navigationController pushViewController:entityController animated:YES];
The problem here is when it pushes to different controller the TabBar is completely hidden and Navigation bar right button is completely Hidden.
I tried to Unhide the tab bar and Navigation bar but no effect. I tried all possibilities but nothing worked.
Can some one please let me know what is right approach to solve this issue.
Thanks In Advance.
Have you tried switching the order of the UINavigationController and the UITabController?
Right now, it seems like you have a UINavigationController with a UITabController "inside" it. So, when you push something else to the UINavigationController, the UITabController is being pushed aside, as it is no longer relevant.
If you were to have the UITabController on the top most level, with the UINavigationController at each of the tabs (or only on the relevant ones), when you'll push another view controller to that UINavigationController, it won't affect the tab bar, since it will still be on the top most level, completely unaffected by the push.
I hope this helps. Good Luck!
Thanks for the help. I resolved the issue by making Tab Bar controller as TOP View and Navigation controller for each view ( as per requirement. I made SearchController separately so that user can search from any where inside the app.
I updated this as it can be help full for those who needs to implement similar kind of requirement.
If there is a better approach of implementation please do provide your comments.
Thanks
I have a third party control that wants me to put a view inside of it. I'm trying to get a UINavigationController containing a series of table views inside of it, but when adding the controls the navigation bar overlaps the tableview by about half a row, which looks dumb.
Here's the code. I'm using the ArcGIS Server iOS SDK to put the navigation controller in a callout box on the map:
IdentifyResultsViewController *idWindow = [[IdentifyResultsViewController alloc] init];
idWindow.results = results;
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:idWindow];
map.callout.customView = nvc.view;
nvc.view.frame = CGRectMake(0, 0, 275, 400);
[map showCalloutAtPoint:self.mapPoint];
Is this a common problem using the UINavigationViewController, or should I look to the third party control?
I actually just had a similar problem with a third party control obstructing my navigation bar. I tried to look into the control but I'm not versed enough to unhide the navigation bar.
What I did may be something you can do too: instead of using the built in UINavigationBar, I kind of built one myself by just putting in a UIView at the top of the page and adding custom buttons to it that performed the functions that I wanted in the bar. This gives you a little more wiggle room around that third party control if you can't find what's causing the issue.
Hope it helps!
I solved this using some simple reordering of code - instead of using initWithRootViewController, I created the navigation view controller, set it's frame manually, and then pushed the view controller on to it:
IdentifyResultsViewController *idWindow = [[IdentifyResultsViewController alloc] init];
idWindow.results = [self filterResults:results];
UINavigationController *nvc = [[UINavigationController alloc] init];
nvc.view.frame = CGRectMake(0, 0, 275, 400);
[nvc pushViewController:idWindow animated:NO];
map.callout.customView = nvc.view;
[map showCalloutAtPoint:self.mapPoint];
This looked simple enough when I set it up, but I can't explain why this gap is present between the status bar and the navigation bar. Also, the contained view looks like it may be properly aligned, and it's just the nav bar that is shifted down. The gap looks like the size of the status bar, so I expect that has something to do with it, but I don't know what.
Here is the code for setting up the navigation controller:
- (void)viewDidLoad
{
[super viewDidLoad];
advancedVC = [[AdvancedSearchFormVC alloc] initWithNibName:#"AdvancedSearchForm" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:advancedVC];
nav.navigationBar.tintColor = [UIColor defaultNavBarTint];
nav.navigationBar.topItem.title = NSLocalizedString(#"SearchTitle", nil);
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"SearchButton", nil) style:UIBarButtonItemStylePlain target:self action:#selector(refreshPropertyList:)];
nav.navigationBar.topItem.rightBarButtonItem = searchButton;
self.view = nav.view;
}
The rootViewController uses a view from a xib file, where I have simulated the status bar, the navigation bar, and the tab bar.
The problem is indeed that the navigation controller always expects to leave room for the status bar, which is the 20 pixel gap. I searched around for a while before I found this solution which works:
//nav is assumed to be a subclass or instance of UINavigationController
nav.view.frame = CGRectOffset(nav.view.frame, 0.0, -20.0);
//you can then add the navigation's view as a subview to something else
I originally found an answer which did this offset to the navigationbar's view, but it didn't work. It works when you do it to the navigation controllers actual view.
I use this technique to add a navigation controller from another nib to an empty view of my main nib, so I can position it anywhere within the main screen as a subview. By using an empty view as a placeholder and positioning frame on my main nib, I create a separate nib and class to manage the navigation, which manages other nibs used to handle their screens. This way I can solve the classic "how do I add a banner, image, or custom views above my navigation controller" while having a navigation controller as a subview...in iOS 5 to be specific.
It's also worth mentioning that I use the app delegate to store and access all the other controllers, so they are retained by a persistant instance which I can access from any class. Create and synthesise some properties in the app delegate of all your controllers, and in viewDidLoad create instances. That way I can reference all the controllers used in my app later anywhere by adding:
//this shows how to store your navigation controllers in the app delegate
//assumes you've added 2 properties (UINavigationController*)"navController" and (UIViewController*)"rootController" in your app delegate
//...don't forget to add #import "AppDelegate.h" to the top of the file
AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[app.navController pushViewController: app.rootController animated:YES];
//now apply the offset trick to remove the status gap
app.navController.view.frame = CGRectOffset(app.navController.view.frame, 0.0, -20.0);
I had the same problem before. The code I used to add UINavigationBar to UIViewController:
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:self];
[self.view addSubview:nc.view];
Solution:
Check the box "Wants Full Screen" with Attributes inspector of your UIViewController.
You can try to set the attribute Under Top Bars unchecked from Attributes section of UIViewController.
As we all know by now, the 20 pixel shift is to provide space for the Status bar on the top.
But infact, the view controllers coordinate system is kept in place and only the navigation bar frame is shifted down by 20 pixels. This makes the navigation bar to actually overlap the top 20 pixels of the view.
Logging the navigation bars frame origin, it will show (0.0, 20.0)
So the solution is to simply reposition the navigation bar's origin to (0.0, 0.0) in ViewWillAppear.
self.navigationController.navigationBar.frame = CGRectMake(0.0, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
Since you're adding advancedVC as a subview of self.view, it is being added inside the frame of self.view which I'm guessing is already compensating for the status bar.
You can probably easily fix this by adding this line:
nav.view.frame = self.view.frame;
Just above this line:
self.view = nav.view;
-
Other Thoughts
I'm not privy to your entire setup, but self.view may not be needed at all. Simply make your advancedVC instance the rootViewController of the UIWindow instance contained in your App Delegate.
The problem was resolved by fixing the way the navigation controller was inserted. Instead of inserting it into a view that had been put onto the tabbar controller, the navigaiton controller should have been put directly onto the navigation controller.
advancedSearchFormVC = [[AdvancedSearchFormVC alloc] initWithNibName:#"AdvancedSearchForm" bundle:nil];
UINavigationController *searchNavController = [[UINavigationController alloc] initWithRootViewController:advancedSearchFormVC];
This is just one controller that is on the tabbar controller, replacing the advancedSearchFormVC at the same time. Then this nav controller was added to the array of controllers that got put onto the tabbar controller.
Sorry for any trouble, but this was one of those problems I can look directly at and not see it. I should have seen this earlier, because I had another nav controller already on the tabbar controller, and it was set up the same way.
Thanks for your assistance.
The problem is that UINavigationController.view should be added to the top view.
Just find the top one and it will be working great.