Reputation: 271
How can I use an UIAlertController inside a TableViewCell
?
Gives me an error does not have a member called "presentViewController"
.
My TableViewController
is named "OrdensCompraTableViewController"
My function:
@IBAction func telefonarCliente(sender: AnyObject) {
var alert = UIAlertController(title: "Fotos em falta!", message: "Tem de introduzir 6 fotos.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
if let phoneCallURL:NSURL = NSURL(string: "tel://") {
let application:UIApplication = UIApplication.sharedApplication()
if (application.canOpenURL(phoneCallURL)) {
application.openURL(phoneCallURL);
}
}
}
Upvotes: 0
Views: 1058
Reputation: 13343
Use telprompt://123456789
instead of creating a UIAlertController
to prompt the user before dialing the phone number.
Upvotes: 1
Reputation: 42449
You can't present a UIViewController
from a UITableViewCell
(it's not a view controller). You have two options:
1 - Assign a delegate to the UITableViewCell
pointing back to its parent view controller and preset the alert on the view controller.
2 - Present the alert on the application's root view controller:
UIApplication.sharedApplication().delegate?.window??.rootViewController?.presentViewController(alert, animated: true, completion: nil)
Upvotes: 1