edwinbosire / SwiflyOverlay

Another Navigation component for iOS. This time written in swift.
MIT License
98 stars 10 forks source link

Unable to reopen menu #1

Closed Kalissaac closed 8 years ago

Kalissaac commented 8 years ago

I have three view controllers (View Controller A, View Controller B and View Controller C) that I want to use my menu with. My storyboard entry point is at VC A. When I tap on the button, I can open up the menu and performSegueWithIdentifier to a different view controller. The problem is, when I tap on the button from the view controller I segued to, the menu doesn't show up and I don't know why. Here is my code from the view controller (I removed the stuff that wasn't relevant):

import UIKit
import Presentr

class ViewControllerA: UIViewController, MenuViewDelegate {

    lazy var menuViewController: MenuViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("menu") as! MenuViewController
    var overlay: OverlayView?

    @IBAction func presentOverlay(sender: AnyObject) {

        menuViewController.delegate = self

        if overlay == nil {
            overlay = OverlayView()
        }

        overlay?.addSubview(menuViewController.view)
        overlay?.open()
    }

    func didSelect(menu: Menu, row: NSIndexPath, inTableView: UITableView) {
        // Reload view based on menu
        if menu.title == "A" {
        } else if menu.title == "B" {
            self.menuViewController.performSegueWithIdentifier("BSegue", sender: nil);
            overlay?.dismissView()
        } else if menu.title == "C" {
            self.menuViewController.performSegueWithIdentifier("CSegue", sender: nil);
            overlay?.dismissView()
        } else if menu.title == "Sign Out" {
            let title = "Are you sure?"
            let body = "Do you really want to sign out?"
            let controller = Presentr.alertViewController(title: title, body: body)
            print("hi")
            let deleteAction = AlertAction(title: "Sign Out", style: .Destructive) {
                try! FIRAuth.auth()?.signOut()
                self.menuViewController.performSegueWithIdentifier("logoutSegue", sender: self)
                self.navigationController?.popToRootViewControllerAnimated(true)
                self.overlay?.dismissView()
            }
            let okAction = AlertAction(title: "Nope", style: .Cancel){ self.overlay?.dismissView() }
            controller.addAction(deleteAction)
            controller.addAction(okAction)
            let presenter = Presentr(presentationType: .Alert)
            customPresentViewController(presenter, viewController: controller, animated: true, completion: nil)

        } else {
        }
    }

    ;override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }
}
edwinbosire commented 8 years ago

Thanks for using this component. I've not run your code but I can quickly spot a few issues with your implementation.

  1. If you perform a segue, does viewController B & C conform to the MenuViewDelegate and subsequently implement their own respective didSelect(...) method?
  2. Instead of performing segues, have you consider view containment? This will allow you to simplify your didSelect(...) method.

Admittedly, I should have created a demo with more than one VC. I will try and do this soon, if its of any help

Kalissaac commented 8 years ago

I appreciate the quick response. For your first question: Yes, all the view controllers have the same code for the MenuViewDelegate and they all have the didSelect() method. As for the second one: I tried using view containment and that still didn't solve the problem. (I was not able to open the menu again.)

edwinbosire commented 8 years ago

@Kalissaac i've implemented the view containment strategy in a second demo, currently available on this branch, Demo2

If that helps you, please let me know and i'll merge it to the main repo.

To get the changes in your local machine do pull & checkout in the SwiftlyOverlay folder

$git fetch $git checkout Demo2

Kalissaac commented 8 years ago

Thanks for all your help. I'm trying it out right now.

Kalissaac commented 8 years ago

The new demo worked. Again, thank you for your help.