Reputation: 89
Having trouble doing this in Swift..Super easy in Objective C. The error I get in the log is this:
2015-01-31 22:16:58.734 fun facts[15208:623304] Unknown class Settings in Interface Builder file.
2015-01-31 22:17:10.783 fun facts[15208:623304] -[UIViewController sendEmail:]: unrecognized selector sent to instance 0x7f9b7bc2fa30
2015-01-31 22:17:10.794 fun facts[15208:623304] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController sendEmail:]: unrecognized selector sent to instance 0x7f9b7bc2fa30'
See my code below. Any ideas what I do wrong?
//////////////////////SEND EMAIL
@IBAction func sendEmail(sender: AnyObject) {
var emailTitle = "Test Email"
var messageBody = "This is a test email body"
var toRecipents = ["yolo@mail.com"]
var mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
mc.setToRecipients(toRecipents)
self.presentViewController(mc, animated: true, completion: nil)
}
func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) {
switch result.value {
case MFMailComposeResultCancelled.value:
println("Mail cancelled")
case MFMailComposeResultSaved.value:
println("Mail saved")
case MFMailComposeResultSent.value:
println("Mail sent")
case MFMailComposeResultFailed.value:
println("Mail sent failure: \(error.localizedDescription)")
default:
break
}
self.dismissViewControllerAnimated(false, completion: nil)
}
}
Upvotes: 0
Views: 850
Reputation: 37300
This sort of error can occur if you accidentally set a view's class to an incompatible custom class; for example, accidentally setting a UIButton
's custom class to "Settings," i.e. a UIViewController
class in this case, may have caused your particular error.
Upvotes: 2