I have a customer tab controller that has a custom icon that when a user clicks a popup menu comes up with 3 choices. When I click the first option it should take me to a new view controller, however when I click it the view controller only appears for a second before disappearing again. I'm not sure why but here is my code for the customer tab bar:
import UIKit
import PopMenu
class TabBarController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
delegate = self
}
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if viewController.title == "for custom action" {
let manager = PopMenuManager.default
let action1 = PopMenuDefaultAction(title: "Scan Barcode", didSelect: { action in
self.performSegue(withIdentifier: "showScanBarcode", sender: nil)
print("\(String(describing: action.title)) is tapped")
})
let action2 = PopMenuDefaultAction(title: "Action 2", didSelect: { action in
print("\(String(describing: action.title)) is tapped")
})
let action3 = PopMenuDefaultAction(title: "Action 3", image: UIImage(named: "wine"), didSelect: { action in
print("\(String(describing: action.title)) is tapped")
})
manager.addAction(action1)
manager.addAction(action2)
manager.addAction(action3)
manager.present()
return false
}
return true
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "mySegue" {
let controller = segue.destination as! myViewController
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
Here is an image showing the flow. User clicks the camera button, then a popup menu appears and when the user clicks on an option I want to take them to a new view controller (not connected to tab bar controller). I setup the first link to go to a new view controller, and it shows for a few seconds then disappears.
You are using different identifier for segue method,
performSegue(withIdentifier: "showScanBarcode", sender: nil)
AND
prepare(for segue: UIStoryboardSegue, sender: Any?)
.
So, please use same identifier. Hope this will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With