Skip to content

AKSwiftSlideMenu, NavigationControllers & UIBarButtonItem BadgeValues conflict #14

@tattva20

Description

@tattva20

I'm creating a shopping app, and this app has a shopping cart.

The shopping cart icon appears in most of the app's views always indicating how many items does the shopping cart has, it's a rightButtonItem inside a navigationItem.

It is now working properly. Except in the screens that are accessed using AKSwiftSlideMenu, the reason is because in all my other views I had to embed the destination view inside a navigation controller. The count of the shopping cart items is loaded when the app starts and it's stored as a global singleton that I access in all the viewDidLoads of my screens.

override func viewDidLoad() {
super.viewDidLoad()
var numeroProducto = String(Carrito.numProd)
navigationItem.rightBarButtonItem?.badgeValue = numeroProducto  
}

To give the cart Button and a badgeValue I'm using the UIBarButtonItem + Badge framework.

The problem is that the AKSwiftSlideMenu uses these methods to segue.

func openViewControllerBasedOnIdentifier(_ strIdentifier:String){
  let destViewController : UIViewController = self.storyboard!.instantiateViewController(withIdentifier: strIdentifier)

  let topViewController : UIViewController = self.navigationController!.topViewController!

  if (topViewController.restorationIdentifier! == destViewController.restorationIdentifier!){
    print("Same VC")
} else {
    self.navigationController!.pushViewController(destViewController, animated: true)
    }
}

and

func slideMenuItemSelectedAtIndex(_ index: Int32) {

let topViewController: UIViewController = self.navigationController!.topViewController!
print("View Controller is : \(topViewController) \n", terminator: "")
switch(index) {
case 0:
    print("Home\n", terminator: "")

    self.openViewControllerBasedOnIdentifier("Home")

    break

case 1:
    print("Play\n", terminator: "")

    self.openViewControllerBasedOnIdentifier("MiCuenta")

    break

case 2:
    print("Play\n", terminator: "")

    self.openViewControllerBasedOnIdentifier("QuienesSomos")

    break

case 3:
    print("Play\n", terminator: "")

    self.openViewControllerBasedOnIdentifier("NuestraCausa")

    break

case 4:
    print("Play\n", terminator: "")

    self.openViewControllerBasedOnIdentifier("Contacto")

    break

case 5:
    print("Play\n", terminator: "")

    self.openViewControllerBasedOnIdentifier("FAQ")

    break

default:
    print("default\n", terminator: "")
  }
}

So the problem is that a new Navigation controller is instantiated programmatically when I segue using the slide menu, but I don't know how to change the badgeValue of that navigation controller, any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions