I have been trying to make a function start after specific tab bar is changed.
My problem is that I am making a movie app and in one of the tab bars you can choose which genres you want the app to search for. However I need to update the request string when the user switches from the genreselector to another tab bar like settings or the movie finder tab bar.
I have looked at using a tab bar controller but i can only see if the user cliked on one of the tab bars and not see when they specifically change from the genreSelector to another tab view item.
Would love if someone could point me in the right direction :)
You can implement the tabBarControllerDelegate method:
func tabBarController(UITabBarController, shouldSelect: UIViewController)
It's called when a specific UIViewController is selected. If the view controller that should be selected is not genreSelector you can go ahead and update the request string.
Related
Good Day,
i am looking for a solution of how to make the UITabbar item can popup a submenu.
What part are you having trouble with? It seem pretty simple. Make custom view controller with a tabBar (don't use UITabBarController), for most tab bar items show the correct viewController (ie add as a childViewController), but for more show a popup (a different childViewController). Remember than when the more popup is dismissed to reselect the current tab on the tabbar.
I have a Tab Bar Navigation controller, for one of the options available on the tab bar I would like to do the following, the option name in this case is "Order History".
I want to have a simple View Controller with an Activity Indicator to get the data from my Firebase database. Once all the data is gathered, I have an if statement. If the query to Firebase did not return any values I would like to segue to another View Controller that will show the user that he/she has not placed any orders yet. However, if the query to Firebase returns any order history data then I would like to segue to a Table View Controller that will display all of the data in an organized way.
The issue I am having is that I would like to have tab bar menu at the bottom of each of the child views mentioned above. I know I can do this by embedding the first view (the one with the Activity Indicator) inside a Navigation Controller. However, I noticed that once I tap on a different tab bar item and then come back to this tab bar item (the "Order History" tab bar item) it does not show the first view with the Activity Indicator to perform the query to the database once again. Instead, it is going back to the last view presented in the Navigation stack which was the view showing the user that he/she has not placed any orders yet. It is important that the query to the database is performed every time to make sure the data is refreshed every time.
I'd appreciate any input on how to best implement this. I am using the storyboard for all of this. Thanks
You can keep the orderHistoryNavController as is as a viewController in the tab bar. Keep a weak reference to the navigation controller in the tab bar, then override UITabbar:didSelectViewController something like this.
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
orderHistoryNavController.popToRootViewController(NO)
}
This will pop to the activity indicator (even if hidden) anytime a new tab is selected.
For a settings view controller, I am currently saving when the user hits the Back Button using viewwilldisappear. However, the settings VC is embedded in a tab bar controller and I've discovered that when the user leaves the VC by moving to another tab, viewwilldisappear does not fire and therefore the settings are not saved. I guess I could save every time someone changes an individual setting, but it would be simpler to save at the end.
Is there any simple way to detect the press of the tab bar controller from within the view controller so I can save settings before leaving if a tab item is pressed?
Take a look at UITabBarControllerDelegate, specifically shouldSelectViewController.
The tab bar controller calls this method in response to the user
tapping a tab bar item. You can use this method to dynamically decide
whether a given tab should be made the active tab.
https://developer.apple.com/reference/uikit/uitabbarcontrollerdelegate?language=objc
I have an application which has 5 tabs. I also have another view which you can access from tab3 via a selection of buttons. I will call it view 3b. View 3b populates with information based on which button the user selected in view 3. After the user puts in all the information required the app automatically takes them back to view 3. I want to add the tab bar to this view(3b) but I do not want it to have its own tab. I just want to use it so the user can navigate out of this view back to the rest of the app if they want to exit the screen early. Does anyone know how I can attach the tab bar to this screen without having a tab added for this screen. I am using Xcode 4.6.2 and am using storyboards to set up my app.
Any help would be appreciated. I've done a bit of searching but everything I find just explains how to use tabs.
Any help would be appreciated. Thanks.
It sounds like you need to use a UINavigationController.
When you set up your UITabBarController, instead of linking the third tab directly to your 3rd view controller, connect it to a UINavigationController, and then set the root view of that UINavigationController as the UIViewController you want as your third tab.
From there, you can set up your buttons to perform a push segue to your second view controller (view 3b from your question). If you do this, not only will you keep the tab bar on view 3b, but a back button will automatically be placed in the top left of the page so the user can simply go back to view 3. If you don't want the navigation bar that appears to be there, you can instead uncheck the "shows navigation bar" checkbox in the UINavigationController's attributes inspector.
I hope this helps!
I have a tab bar controller with a number of tabs/views. I have added a "Help" bar button item to the tab bar controller's top navigation bar.
How do I handle clicks of this button, ideally depending on which view I am in at the time?
I am simply going to pop up an alert when it is clicked, ie. No navigation required.
Ideally, this "help" tab should not change its behaviour depending on context, i.e., what tab was previously selected. The user will get confused because the content will not be constant.
If you raise a "pop up alert" when the tab is selected, this also seems like a basis for rejection because of bad UX. Selecting a tab should display a new view for that tab. You'd also have to deal with how to move the user back to the previous tab silently, and/or not change the selected tab index. Again, this is troublesome UX.
If you insist on going with this design -- which I believe will get your app rejected -- you can use a UITabBarControllerDelegate to control the behaviour of the UITabBarController.
I recommend you change your design instead.
I've managed to get this working. I think you misunderstood: I have a tab bar control which operates normally by pushing views based on the tab selected. I simply wanted a help button on the right of the navigation bar that would open an alert with information about the tab you happen to be in at the time. I have done it like this:
In viewDidAppear of each view pushed by the tab bar controller:
UIBarBarButtonItem *helpButton = [[UIBarBarButtonItem alloc] initWithTitle:#"Help" style:UIBarButtonItemStylePlain target:self action:#selector(helpButtonPressed))];
self.tabBarController.navigationItem.rightBarButtonItem=helpButton;
I then have the helpButtonPressed function to handle the button click, in my case by popping up and alert with some help info regarding the tab.