Saturday, 4 May 2019

View Controller disappearing after Segue

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.

enter image description here



from View Controller disappearing after Segue

1 comment:

  1. http://www.wizweb.in

    Wizweb Technology is a leading software development company custom website design, software development, SMS Provider, Bulk sms, transactional sms, promotional sms, mobile app development, Hosting Solution, seo(search engine optimization) and Digital marketing etc.

    ReplyDelete