Tabbar more view controller iPhone - ios

I would like to know if there is a way to ensure that every time user presses on the "More" button in tabbar, he or she will be presented with list of views that are in there, not to show current view in which user is in. What I would like to get is always have the list of views on every time user press the "More" button.

This seems to work, but there may be some edge cases that I didn't consider.
In the appDelegate:
self.tabBarController.delegate = self;
...
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[[viewController navigationController] popToRootViewControllerAnimated:NO];
}

Related

blank Tab Bar item as link

Alright so here is the deal. I have 5 tabs, 3 of them are just links. So when the user clicks on them, it actually brings them to a website using this:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{...}
So the tab bar item pretty much works as a button.
The links work just fine but the problem is that I don't want a view loaded on the click. So initially I added some [UIViewController alloc] for self.viewController (in the tab bar controller). Those view controllers are blank but they allow me to add the icon like so:
UIViewController *vc = [UIViewController alloc];
[vc1.tabBarItem setImage:[[UIImage imageNamed:#"tab-fb"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
vc1.title=#"Facebook";
All of this works fine, but when the user clicks on it, there is a blank black view. I understand this is normal, but how do I get rid of that? I want the user to be able to stay on the current view, but be led to the link.
I tried doing something like this:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
selectedIndex=[[tabBar items] indexOfObject:item];
if(selectedIndex == 1){
[self setSelectedIndex:0]; //RIGHT HERE
//...code to go to link...
}
}
but for some reason, the program does not respond to [self setSelectedIndex:0];
Any tips?
This does not work for me either in my tab bar.
However, this approach might work for you. In your app delegate didFinishLaunchingWithOptions:
MyTabBarController.delegate = self;
Then implement this delegate method in your app delegate:
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
In the method you can check for the VC like this:
if ([tabBarController.viewControllers indexOfObject:viewController] == indexOfTabToBlock) return false;
This effectively blocks the switch to that tab.
You would have to find some way to communicate this tap to the main view controller that you want to keep the user on so that it can process the link however you want. You could use a notification for example.

Which NavigationController Method runs on every view reload (TabBarItem)

I have a NavigationController then a TabBarController which has Four Tabs.
I wanted to display Different titles on TopBar when a Different Tab is selected.
One way was to Embed each TabBarItem View into Navigation Controller but for some reason this doesn't seems the correct way, i wanted to apply this via code.
I managed accomplish this by using this code: (Products_ViewController.m custom class)
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UINavigationController *navCon = (UINavigationController*) [self.navigationController.viewControllers objectAtIndex:0];
navCon.navigationItem.title = #"Products";
}
But the problem is now when a tab is clicked First time, it changes the title but then it doesn't. I then applied the same code on -(void)viewDidAppear{} but still the same result.
How can i manage to display navigation top bar title (or run the above code) whenever the tab bar item is clicked or the view is shown?
Thanks!
You could implement the UITabBarControllerDelegate in the Products_ViewController.m class and execute your code in the tabBarController:didSelectViewController: method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UINavigationController *navCon = (UINavigationController*) [self.navigationController.viewControllers objectAtIndex:0];
navCon.navigationItem.title = #"Products";
}
In the viewDidLoad method you have to set the delegate to self.

Prevent UINavigationController from popping on double tap of UITabBarController

I have a UITabBarController in the root of my storyboard with three tabs. One of the tab is used to display the user information. I have set this tab to transition to the register/login page if the user has not registered. But the ViewController gets popped(and corrupts the Navigation Bar) when I double tap the tab icon. I cannot use the modal transition as it hides the TabBarController. What is the best solution to solve this issue?
You can use 'shouldSelectViewController' delegate of TabViewConroller to check if the selected viewController is same as the clicked one and skip it accordingly.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if(viewController == tabBarController.selectedViewController)
{
return NO;
}
}

iOS - NavigationBar showing on child controller, hidden on parent controller

I have implemented a custom version of a search form that behaves a lot like a UISearchBar with a scope bar (but is actually pieced together programatically for UI reasons). The screen loads with a TextField, you tap in the TextField and the navigation bar animates up off the screen, the text field moves up and a segmented control appears for filtering results.
Anyway, that all works, but when I tap on one of the search results my code pushes a new ViewController. The problem is that new controller gets pushed without a navigation bar (because I used [[self navigationController] setNavigationBarHidden:YES animated:YES] when switching to the search state).
I can show the navigation bar as the new ViewController gets pushed, or even animate it in as the transition to the new ViewController appears - but all those solutions look clunky. I want it to work as if you were using a UISearchBar (actually more like the email app) in that the restored navigation bar appears to just slide in from the right as if it's part of the child view controller.
I'm hoping there'll be a simple fix... thanks
For anyone that comes to this, the solution is to make your controller the delegate of the UINavigationController, then show or hide the nav bar in your delegate methods.
Your controller needs to implement the protocol:
#interface MYSearchController() <UINavigationControllerDelegate>
Then in -(void)viewDidLoad assign your controller as the delegate:
[self navigationController].delegate = self;
Finally, implement a method like this:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if(viewController == self)
{
if(_searchState && ![self navigationController].navigationBarHidden)
{
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
}
else
{
if([self navigationController].navigationBarHidden)
{
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
}
}

Is it possible to pop to a specific view in the poppover when dismissing popover?

I have a popover that has a main view that is used to pick from several sub-views and I'd like to reset the popover to the main view when the user taps outside of the popover and closes the window.
For example, the main popover view has Options, Categories, WordList, and Results. I'd like to make it so that the next time the user invokes the popover, they go to the main view rather than back to the view they were on when they last closed the popover.
If I'm only one level deep, I can use
- (void)viewWillDisappear:(BOOL)animated {
[[self navigationController] popToRootViewControllerAnimated:YES];
[super viewWillDisappear:animated];
}
But if I'm deep in a hierarchy, e.g. WordList:Category:Words I can't pop to root in WordList or Category since when the view disappears, I want to go to the next level down. If I use the code listed above, I can't get down a level. I pop to the root view.
What I'd like is to be able to tell the popover view to pop to its root when it's dismissed. Something like this:
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[[self popover] popToRootViewControllerAnimated:YES];
[self.popoverController dismissPopoverAnimated:YES];
}
Any thoughts?
I believe that what you want is UIPopoverController's contentViewController property, which will be whatever view controller you initialized the popover with--most likely that navigation controller. This...
[self.popover.contentViewController popToRootViewControllerAnimated:YES];
...should do the trick for you.
When initializing the popover, I test to see if it already exists. If so, I skip the initialization and go directly to the popover. That's why, when the popover is dismissed, it stays in whatever view the user left it in.
To make it start at the first view, I just need to set the popover to nil.
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popOverController {
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
Now when the user invokes the popover, it creates a new set of views, starting with the main menu.

Resources