ios - How would I create a UIAlertView in Swift? -


i have been working create uialertview in swift, reason can't statement right because i'm getting error:

could not find overload 'init' accepts supplied arguments

here how have written:

let button2alert: uialertview = uialertview(title: "title", message: "message",                      delegate: self, cancelbuttontitle: "ok", otherbuttontitles: nil) 

then call i'm using:

button2alert.show() 

as of right crashing , can't seem syntax right.

from uialertview class:

// uialertview deprecated. use uialertcontroller preferredstyle of uialertcontrollerstylealert instead

on ios 8, can this:

let alert = uialertcontroller(title: "alert", message: "message", preferredstyle: uialertcontrollerstyle.alert) alert.addaction(uialertaction(title: "click", style: uialertactionstyle.default, handler: nil)) self.presentviewcontroller(alert, animated: true, completion: nil) 

now uialertcontroller single class creating , interacting knew uialertviews , uiactionsheets on ios 8.

edit: handle actions:

alert.addaction(uialertaction(title: "ok", style: .default, handler: { action in     switch action.style{     case .default:         print("default")      case .cancel:         print("cancel")      case .destructive:         print("destructive")     } })) 

edit swift 3:

let alert = uialertcontroller(title: "alert", message: "message", preferredstyle: uialertcontrollerstyle.alert) alert.addaction(uialertaction(title: "click", style: uialertactionstyle.default, handler: nil)) self.present(alert, animated: true, completion: nil) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -