So I'm new to iOS Development and I'm finally onto this step: https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/WorkWithViewControllers.html#//apple_ref/doc/uid/TP40015214-CH6-SW1
I've followed the guide step-by-step and for some reason, when I run my app, I click on the Image View and nothing pops up. My code is exactly like Apple's with the exception of nameTextField
being businessNameTextField
and businessNameLabel
. Here's my ViewController.swift
file
//
// 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)
}
}
My AppDelegate.swift
file is is the default when creating the project, so nothing to show there.
Here's the Main.storyboard
:
I'm trying to avoid just deleting the app and starting over because I want to get in the habit of troubleshooting and learning what I'm doing wrong.
From what I understand, and feel free to correct me if I'm wrong, when the user clicks on the Image View, it's calling the selectImageFromPhotoLibrary
function from which I've defined under Actions, and everything is supposed to go from there.
Edit
It looks like the issue may have been the "User Interaction Enabled" checkbox that I forgot to check. It's the only thing I changed since posting the question and apparently it's working now.