Objective-C how to present an action sheet from tab bar that overlaps the current view?

536 Views Asked by At

I'd like to add an action sheet that appears when tab bar center item is clicked. like in this example: this is how it shows when center item is clicked

i have added the tab bar from storyboard and its working fine. the hard part of it is how to keep the previous view and overlay the action sheet. thanks in advance.

2

There are 2 best solutions below

3
rv7284 On BEST ANSWER

use this delegate function to intercept tab selection

for swift 3

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
    if self.tabBarController.customizableViewControllers.index(of: viewController) == 2 {
       //display action sheet
       return false
    }
    return true
}

for objective c

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
//same logic above
}
2
Andreas Oetjen On

You could simply create an empty view controller, and present the action sheet in viewDidAppear. But you have to think of what to do (e.g. which view controller to display)

  • after the user chose an option
  • if the user cancels the action