gpt4 book ai didi

xcode - 类型 'ViewController' 不符合协议(protocol) 'UIDocumentPickerDelegate' swift 2

转载 作者:行者123 更新时间:2023-11-28 06:56:39 25 4
gpt4 key购买 nike

类型“ViewController”不符合协议(protocol)“UIDocumentPickerDelegate”。我无法让 UIDocumentPickerDelegate 使其符合要求。有人可以帮助并解释我如何解决这个问题。 Swift 总是这样做。

import UIKit

class ViewController: UIViewController, UIDocumentPickerDelegate {

@IBOutlet var imageView: UIImageView!

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.
}

@IBAction func importFiles(sender: UIBarButtonItem) {

var documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: ["public.image"], inMode: UIDocumentPickerMode.Import)

documentPicker.delgate = self

documentPicker.modalPresentationStyle = UIModalPresentationStyle.FullScreen

self.presentedViewController(documentPicker, animated: true, completion: nil)
}

func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtUrl url: NSURL){

if (controller.documentPickerMode == UIDocumentPickerMode.Import){

self.imageView.image = UIImage(contentsOfFile: url.path!)
}
}
}

最佳答案

当我的部署目标是 iOS 7.1 时,我遇到了同样的编译错误。您收到此错误的原因可能是因为 UIDocumentPickerDelegate 仅适用于 iOS 8 及更高版本。您还拼错了委托(delegate)属性分配和 self.presentedViewController(documentPicker, animated: true, completion: nil)

关于xcode - 类型 'ViewController' 不符合协议(protocol) 'UIDocumentPickerDelegate' swift 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33449690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com