In iOS 8 the UIAlertView is deprecated. Now UIAlertController is a single class for creating and interacting with what we knew as UIAlertView.
We have to create alert as follows.
[code language=”obj-c”]
var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
[/code]
We can also create handler for handle the events on alert.
[code language=”obj-c”]
var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in
switch action.style{
case .Default:
println("default")
break
case .Cancel:
println("cancel")
break
case .Destructive:
println("destructive")
break
}
}))
self.presentViewController(alert, animated: true, completion: nil)
[/code]
Happy Coding 🙂
For more iOS tutorials visit iTuts.