ios - 在 Swift 中使用未解析的标识符 'present'(Apple 教程)

标签 ios swift ibaction presentviewcontroller

我只是通过制作 FoodTracker 应用程序来遵循 Swift 和 Xcode 的官方 Apple 介绍教程。 我遇到了这个错误(见标题)。

这是 Xcode 7.2.1 我导入了 UIKit

这是出现问题的代码。我有所有的类协议(protocol)和代表等等。

  @IBAction func selectImageFromPhotoLibrary(sender: UITapGestureRecognizer) {
    nameTextField.resignFirstResponder()
    // UIImagePickerController is a view controller that lets a user pick media from their library.
    let imagePickerController = UIImagePickerController()
    // Only allow photos to be picked, not taken.
    imagePickerController.sourceType = .PhotoLibrary
    // Make sure ViewController is notified when the user picks an image.
    imagePickerController.delegate = self
    present(imagePickerController, animated: true, completion: nil)
}

我将不胜感激,因为我刚刚开始学习这门语言!

最佳答案

在你的情况下(你使用的是 xcode 7 -> swift 2)它必须是:

presentViewController(imagePickerController, animated: true, completion: nil)

现在您正在使用 swift3 语法。

关于ios - 在 Swift 中使用未解析的标识符 'present'(Apple 教程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41537168/

相关文章:

ios - 在 Xcode 上创建重复的 outlets/actions

iphone - 将 int 传递给新的 ViewController

ios - 无法选择或打印搜索栏过滤数组

swift - 如何快速编写 pow() 并修复错误?

ios - Swift 单元测试 IBAction

xcode - IBAction 周围的单引号

ios - 从后台返回时未调用 UITextView 委托(delegate)方法 textViewDidChangeSelection

ios - 在 iOS 上使用 Cordova WKWebView 插件时,Ajax 调用失败,HTTP 状态为 0

json - Swift,循环 JSON 返回 Null

swift - 如何以编程方式将 UILabel 和 UiImageView 添加到 TableView 单元格内的 UIView?