Maulik Maulik - 8 months ago 82
iOS Question

How can i push pop in swreveal view controller in ios?

I have an app like Facebook. I want to push and pop in swreveal view controller. How can achieve this? Check following image.

enter image description here

Any help will be appreciated.

Answer Source

I would have a storyboard like this:

enter image description here

In LoginViewController:

    @IBAction func skip(_ sender: Any) {
    // Show dashboard

    let sb = UIStoryboard(name: "Main", bundle: nil)
    let controller = sb.instantiateViewController(withIdentifier: "DashboardNavigationController")

    revealViewController().setFront(controller, animated: true)

@IBAction func validateUser(_ sender: Any) {
    // show profile

    // Here test for valid user name and password
    // If OK
    let sb = UIStoryboard(name: "Main", bundle: nil)
    let dashboardNC = sb.instantiateViewController(withIdentifier: "DashboardNavigationController") as! UINavigationController

    let profileVC = sb.instantiateViewController(withIdentifier: "ProfileViewController")
    dashboardNC .pushViewController(profileVC, animated: false)

    revealViewController().setFront(dashboardNC, animated: true)

@IBAction func dismissKeyboard(_ textField: UITextField) {

In MenuTableViewController (SideMenu):

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

    // ...
    let dashboardNC = revealViewController().frontViewController as! UINavigationController
    let nc = revealViewController().frontViewController as! UINavigationController
    let vc = nc.topViewController

    if !(vc is ProfileViewController) {
        // Instantiate controller from story board
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let controller = sb.instantiateViewController(withIdentifier: "ProfileViewController")
        dashboardNC.pushViewController(controller, animated: false)

    // Push it with SWRevealViewController
    revealViewController().pushFrontViewController(dashboardNC, animated: true)


class DashboardViewController: UIViewController {

@IBOutlet weak var revealButton: UIBarButtonItem!
@IBOutlet weak var rightButton: UIBarButtonItem!

override func viewDidLoad() {
    super.viewDidLoad() = revealViewController()
    revealButton.action = #selector(SWRevealViewController.revealToggle(_:)) = revealViewController()
    rightButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))


    revealViewController().rearViewRevealOverdraw = 0
    revealViewController().rightViewRevealOverdraw = 0

Not Objective-C but you can easily translate!