我正在尝试创建一个可以“撰写”假推文的应用,但我的代码似乎没有将用户选择的图像添加到我为Twitter个人资料图片设置的UIImageView中。
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")
}
}
}
它似乎对UIImageView ...帮助没有任何影响。
答案 0 :(得分:1)
将didFinishPickingMediaWithInfo
嵌套方法移动为ViewController
类可以解决问题。