R.AlAli
R.AlAli

Reputation: 85

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

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.

Upvotes: 2

Views: 575

Answers (2)

rv7284
rv7284

Reputation: 1102

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
}

Upvotes: 1

Andreas Oetjen
Andreas Oetjen

Reputation: 10199

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

Upvotes: 0

Related Questions