所以我是iOS开发的新手,我终于走到了这一步:https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/WorkWithViewControllers.html#//apple_ref/doc/uid/TP40015214-CH6-SW1
我一步一步地按照指南操作,出于某种原因,当我运行我的应用程序时,我点击了图像视图,没有弹出任何内容。我的代码与Apple的代码完全相同,但nameTextField
为businessNameTextField
和businessNameLabel
除外。这是我的ViewController.swift
文件
//
// ViewController.swift
// Example (Sample 1)
//
// Created by lewlsaucengravy on 4/9/17.
// Copyright © 2017 Example. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
//MARK: Properties
@IBOutlet weak var businessNameLabel: UILabel!
@IBOutlet weak var businessTextField: UITextField!
@IBOutlet weak var photoImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
businessTextField.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK: UITextFieldDelegate
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// Hide the keyboard.
textField.resignFirstResponder()
return true
}
func textFieldDidEndEditing(_ textField: UITextField) {
businessNameLabel.text = textField.text
}
//MARK: UIImagePickerControllerDelegate
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
// Dismiss the picker if user cancelled.
dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// The info dictionary may contain multiple representations of the image. You want to use the original.
guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}
// Set photoImageView to display the selected image.
photoImageView.image = selectedImage
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
//MARK: Actions
@IBAction func completeProfile(_ sender: UIButton) {
businessNameLabel.text = "test"
}
@IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) {
// Hide the keyboard.
businessTextField.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
present(imagePickerController, animated: true, completion: nil)
}
}
我的AppDelegate.swift
文件是创建项目时的默认文件,因此无需显示任何内容。
这里是Main.storyboard
:
我真的试图避免删除应用并重新开始,因为我想养成故障排除的习惯并了解我在这里做错了什么。
根据我的理解,如果我错了,请随时纠正我,当用户点击图片视图时,它会调用selectImageFromPhotoLibrary
函数,我可以从中查看SQLCmd -S<<SERVERNAME\INSTANCENAME>> -Q "Execute dbo.YourStoredProcedure"
函数。在动作下定义,一切都应该从那里开始。但是,我不确定我在这里失踪了什么,也不想重新开始。
修改
看起来问题可能是&#34;用户互动已启用&#34;复选框,我忘了检查。这是我发布问题后我唯一改变的事情,显然它现在正在工作。谢谢你的帮助!