Reputation: 9
I am trying to make an app in which you can 'compose' fake tweets, but my code seems to not add an image picked by a user to the UIImageView I have set up for the twitter profile picture.
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{
@IBOutlet weak var twitterName: UILabel!
@IBOutlet weak var twitterUsername: UILabel!
@IBOutlet weak var twitterProfilePic: UIImageView!
@IBOutlet weak var twitterTweet: UILabel!
@IBOutlet weak var inputTwitterName: UITextField!
@IBOutlet weak var inputTwitterUsername: UITextField!
@IBOutlet weak var inputTweet: UITextField!
@IBAction func chooseTwitterImage(_ sender: Any) {
let profilePic = UIImagePickerController()
profilePic.delegate = self
profilePic.sourceType = UIImagePickerControllerSourceType.photoLibrary
profilePic.allowsEditing = false
self.present(profilePic, animated: true)
}
@IBAction func makeTweetButton(_ sender: Any) {
twitterName.text = (inputTwitterName.text)!
twitterUsername.text = (inputTwitterUsername.text)!
twitterTweet.text = (inputTweet.text)!
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let profilePic = info[UIImagePickerControllerOriginalImage] as? UIImage
{
twitterProfilePic.image = profilePic
}
else
{
print("ERROR PICKING IMAGE")
}
}
}
It doesn't seem to make any difference to the UIImageView... Help.
Upvotes: 1
Views: 109
Reputation: 3941
Moving the didFinishPickingMediaWithInfo
nested method to be a class of ViewController
solves the problem.
Upvotes: 1