Button Alerts With UIAlertController In Swift 4



-- Responding To User Interaction With Actions (.actionSheet)




@IBAction func bMasuk(_ sender: Any) {
        
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
        
        alert.addAction(UIAlertAction(title: "Upload", style: .default, handler: nil))
        alert.addAction(UIAlertAction(title: "Contoh Foto", style: .default, handler: { action in
            
            let vc = ContohFotoViewController()
            self.present(vc, animated: true, completion: nil)
            
        }))

        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        
        self.present(alert, animated: true)
    }


-- use alert notif (.alert)




        @IBAction func bMasuk(_ sender: Any) {
        
            
            let alert = UIAlertController(title: "Login failed", message: "Your text", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "Close", style: .default, handler: { (action: UIAlertAction) in
                print("OK")
            }))
            
            self.present(alert, animated: true, completion: nil)
            print("need text")
            
       
    }

This my note as my problem and solution @luffyselah

No comments: