matt koder
matt koder

Reputation: 117

SWRevealViewController won't work after I go to the child of view controller and go back to the previous view controller

I'm working with SWRevealViewController. And I've fully implemented through application slide out main menu. But when I go to one VC which has a child from which I can go back, the self.revealViewController() returns nil for previous/parent VC. And button for main menu doesn't work anymore. I'm programming in Swift. Image below shows navigation with VCs. I have a UITableviewcontroller Projects and + button for adding new Project. After tap on +, new VC Add new project is presented. If I tap Cancel button, VC Projects is presented but main menu button doesn't work and I can't open main menu. Can anyone help me with this problem? Thanks for your time and help.

Navigation

This is the code, beginning of the class ProjectsView where I set the SWViewController for every VC.

class ProjectsView: UITableViewController {

    @IBOutlet var mainMenuBttn: UIBarButtonItem!

    var projects: [String] = ["Project1", "Project3", "Project3"];

    override func viewDidLoad() {
        super.viewDidLoad()

        if self.revealViewController() != nil {
            mainMenuBttn.target = self.revealViewController()
            mainMenuBttn.action = "revealToggle:"
            self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        }

    }

...

Upvotes: 3

Views: 1004

Answers (1)

beyowulf
beyowulf

Reputation: 15331

You don't need a segue from add new project to your initial navigation controller. Create an IBAction for your cancel button like:

@IBAction func cancel(sender: AnyObject) {
       self.dismissViewControllerAnimated(true, completion: nil)
    }

Same for the done button. As it is now, you are creating a new instance of ProjectsView every time you return from Add new project.

Upvotes: 3

Related Questions