Xcode - 无法采用协议 [英] Xcode - Cannot Adopt Protocol
问题描述
对此的帮助将不胜感激.
我想从 iOS 中的应用程序内发送短信.
在 Xcode 中,我完成了以下操作:
在Link Binary With Library中添加了一个参考:
MessageUI.framework
在 ViewController.swift 中,我添加了导入:
import MessageUI
但是,当我尝试添加委托时...
class ViewController: UIViewController, MFMessageComposeViewControllerDelegate {覆盖 func viewDidLoad() {super.viewDidLoad()//在加载视图后做任何额外的设置,通常是从笔尖.}覆盖 func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()//处理任何可以重新创建的资源.}}
我收到此错误:
类型 'ViewController' 不符合协议 'MFMessageComposeViewControllerDelegate'
<小时>更新
按照安东尼奥的建议解决了.我添加了这个:
func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult 结果: MessageComposeResult) {}
这意味着您还没有实现协议中定义的方法.查看文档以了解您必须实施的内容.>
在这种情况下,它只是一种方法:
func messageComposeViewController(_ controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult)
Help on this would be much appreciated.
I would like to send an SMS message from within an app in iOS.
In Xcode, I have done the following:
Added a reference in Link Binary With Library:
MessageUI.framework
In ViewController.swift I have added the import:
import MessageUI
However, when I try to add the delegate ...
class ViewController: UIViewController, MFMessageComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I get this error:
Type 'ViewController' does not conform to protocol 'MFMessageComposeViewControllerDelegate'
Update
Solved by following Antonio's advice. I added this:
func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
}
That means you have not implemented the methods defined in the protocol. Look at the documentation to know what you have to implement.
In this case, it's just a method:
func messageComposeViewController(_ controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult)
这篇关于Xcode - 无法采用协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!