I have a tableView
and viewController
. I need to add a photo with image picker(i already done that) and then I need to save it with a description as a new post in my tableView. What is the best way to do that?
I have already found an information how to add text as a new cell in tableView
, but that is not i want to have.
Here is my code
@IBAction func photoButton(_ sender: UIButton){
let vc = UIImagePickerController()
vc.sourceType = .photoLibrary //PHPpicker
vc.delegate = self
vc.allowsEditing = true
present(vc,animated: true)
}
@IBAction func saveButtonPressed(_ sender: UIButton){
}
extension NewPostScreenController : UIImagePickerControllerDelegate , UINavigationControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
UIImagePickerController.InfoKey(rawValue: "")
if let image = info[UIImagePickerController.InfoKey(rawValue: "UIImagePickerControllerEditedImage")] as? UIImage {
ChangeImage.image = image
}
picker.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
}
What should i add to saveButtonPressed
?
2
Answers
My advice is make sure you break down the problem into parts. Your solution is probably going to require at least these a few things:
Remember that you need implement a UITableViewCell in your tableView to show the posts.
Now, to save post and that these are not deleted when closing the application, i recommend using UserDefaults or Core Data to save the post only in your phone, or use the Firebase to save the post in a data cloud.
With firebase you can save your data without make a server code.
Firebase Page
https://firebase.google.com