Xcode - 无法采用协议(protocol)

标签 xcode swift

在此方面的帮助将不胜感激。

我想从 iOS 应用程序中发送短信。

在 Xcode 中,我做了以下事情:

在 Link Binary With Library 中添加了一个引用:

MessageUI.framework

在 ViewController.swift 中我添加了导入:

import MessageUI

但是,当我尝试添加委托(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.
    }


}

我收到这个错误:

类型“ViewController”不符合协议(protocol)“MFMessageComposeViewControllerDelegate”


更新

按照安东尼奥的建议解决了。我添加了这个:

func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
}

最佳答案

这意味着你还没有实现协议(protocol)中定义的方法。看documentation了解您必须实现的内容。

在这种情况下,它只是一个方法:

func messageComposeViewController(_ controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult)

关于Xcode - 无法采用协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26983222/

相关文章:

iOS:在 WebView 中播放嵌入式剪辑时静音

objective-c - 从其他现有类访问 NSMutableArray

iphone - 当我在 Cocoa Touch 中加载一个新 View 时,它会将所有内容向上移动大约 20 像素

swift - 将 NSViewController 的 View 显示为 NSView 的(NSScrollView) subview

Xcode:构建失败,但没有错误消息

ios - 如何让单元格中的内容 View 占据整个单元格?

ios - 如何播放iOS系统声音并取消回调

ios - 哪个更快? Swift 的 .filter 还是 NSPredicate?

swift - 沙箱发送 AppleEvent 失败

iOS 图表 : Bar chart spacing and position