Maulik Maulik - 8 days ago 6
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

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) {
    textField.resignFirstResponder()
}

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)
}

DashboardViewController:

class DashboardViewController: UIViewController {

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

override func viewDidLoad() {
    super.viewDidLoad()

    revealButton.target = revealViewController()
    revealButton.action = #selector(SWRevealViewController.revealToggle(_:))

    rightButton.target = revealViewController()
    rightButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))

    revealViewController().tapGestureRecognizer()
    revealViewController().panGestureRecognizer()

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

Not Objective-C but you can easily translate!