当前位置:  开发笔记 > IOS > 正文

Swift教程foodtracker:没有调用tap手​​势方法

如何解决《Swift教程foodtracker:没有调用tap手​​势方法》经验,为你挑选了1个好方法。

我正在玩Foodtracker的苹果快速教程,并尝试用点击手势打开照片库.

//
//  ViewController.swift
//  FoodTracker
//
import UIKit

class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    // MARK: Properties

    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var mealPhotoView: UIImageView!

    // MARK: UIImagePickerControllerDelegate
    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        // Dismiss the picker if the user canceled.
        dismissViewControllerAnimated(true, completion: nil)
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        // The info dictionary contains multiple representations of the image, and this uses the original.
        let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage

        // Set photoImageView to display the selected image.
        mealPhotoView.image = selectedImage

        // Dismiss the picker.
        dismissViewControllerAnimated(true, completion: nil)
    }

    // MARK: Actions

    @IBAction func selectImageFromPhotoLibrary(sender: UITapGestureRecognizer) {
        print("selectImage called!")
        // Hide the keyboard.
        nameTextField.resignFirstResponder()

        // UIImagePickerController is a view controller that lets a user pick media from their photo 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

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

    @IBAction func setDefaultLabelText(sender: AnyObject) {
        nameLabel.text = "Default Meal name"

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Handle the user input on textfield through delegate callback (self == this)
        nameTextField.delegate = self
    }

    // MARK: UITextFieldDelegate
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        // Hide the keyboard.
        textField.resignFirstResponder()
        return true
    }

    func textFieldDidEndEditing(textField: UITextField) {
        nameLabel.text = textField.text
    }

}

无论如何,当模拟器启动时,我点击照片,图库视图不会显示.我甚至看不到我的调试信息.

我已经删除了插座和操作,并通过添加UIImageView Outlet再次完成整个过程,添加手势识别器,添加手势识别器的操作但仍然没有发生它应该发生的事情.



1> Stefan..:

我发现了问题 - 我没有启用默认情况下设置为false的用户交互.

推荐阅读
可爱的天使keven_464
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有