Skip to content

How to add AlertView in didselect sidemenu cell clicked? #132

@KaranVakharia789

Description

@KaranVakharia789

I want to add alertView with done and cancel button but i clicked cell Logout menu at that time my current Viewcontroller popToViewController Login Screen and after show Alert but i need on done button popToViewController my code

override func viewDidLoad() {
    super.viewDidLoad()
        sideMenuController?.cache(viewControllerGenerator: {
            self.storyboard?.instantiateViewController(withIdentifier: "LoginVC")
        }, with: "1")
    sideMenuController?.delegate = self
}

and below code in didSelectRow

    let refreshAlert = UIAlertController(title: GlobalConstants.APPNAME, message: "Are you sure you want to logout?", preferredStyle: UIAlertController.Style.alert)
    refreshAlert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { (action: UIAlertAction!) in
        print("Handle Ok logic here")
       
        if #available(iOS 13.0, *) {
            let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyBoard.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC
            self.navigationController?.popToViewController(vc, animated: true)
        } else {
            // Fallback on earlier versions
            let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyBoard.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC
            self.navigationController?.popToViewController(vc, animated: true)
        }
        
    }))
    
    refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
        print("Handle Cancel Logic here")
    }))
    
    present(refreshAlert, animated: true, completion: nil)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions