jefferyleo
jefferyleo

Reputation: 650

From ViewController navigate back to SWRevealViewController Front Page

Navigation from view controller back to SWReveal Front Page

As you can see in the picture, there're 3 controllers at the bottom which are (HomeTableViewController, NavigationViewController and NewsViewController)

HomeTableViewController is the Main Page which I'm using the SWRevealViewController and set it as a front page. (sw_front)

After I've selected a row in HomeTableViewController, it can navigate to NewsTableViewController. However, I've added a back button in the NewsViewController to navigate back to the previous page which is HomeTableViewController, I'm not manage to do that with this code.

In the HomeTableViewController navigate to NewsViewController by selected a row

@IBAction func btnBack(sender: AnyObject)
{
    let home = HomeTableViewController()
    self.presentViewController(home, animated: true, completion: nil)
}

In the NewsViewController press back button back to previous page

@IBAction func btnBack(sender: AnyObject)
{
    let home = HomeTableViewController()
    self.presentViewController(home, animated: true, completion: nil)
}

If I pressed the back button in the NewsViewController, this error appeared.

fatal error: unexpectedly found nil while unwrapping an Optional value

self.revealViewController().rearViewRevealWidth = 200

This code has an error and is located in the HomeTableViewController. I hope that someone could help me on this. Thank you.

Upvotes: 0

Views: 1782

Answers (3)

jefferyleo
jefferyleo

Reputation: 650

https://github.com/John-Lluch/SWRevealViewController/issues/516#issuecomment-160590440 This solve my issue. Delete the navigation controller between the Home and News Controller, and use the push Segue from Home to NewsViewController.

Upvotes: 0

grandboum
grandboum

Reputation: 642

You are getting this error because you are creating new HomeTableViewController in btnBack (and this new controller probably doesn't have revealViewController). There is no need to do this. You can just call self.dismissViewControllerAnimated(true, completion:{}); as Islam Q. suggested:

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

Upvotes: 0

Islam
Islam

Reputation: 3734

You need to dismiss the presented viewController:

@IBAction func btnBack(sender: AnyObject)
{
    let home = HomeTableViewController()
    self.dismissViewControllerAnimated(true, completion:nil);
}

Upvotes: 0

Related Questions