【发布时间】:2017-12-19 04:16:01
【问题描述】:
我是一个初学者,我不确定如何使用 alamofire 将我的图像数组提交到我的数据库。以下是表单加载时的代码
override func viewDidLoad()
{
super.viewDidLoad()
// adding page image into the image square
for i in 1...3
{
var imgView : UIImageView!
imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
imgView.contentMode = .scaleAspectFit
imgView.tag = i
imgView.image = UIImage(named: "page.png")
imageArray.add(imgView)
}
videoView.isHidden = true
photoView.type = iCarouselType.coverFlow2
photoView.reloadData()
}
用户选择/拍照后,图像将替换 page.png .. 一切正常。下面是替换代码
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
self.selectedImageView.image = chosenImage
imageArray.replaceObject(at: self.selectedImageView.tag-1, with: self.selectedImageView)
photoView.reloadData()
dismiss(animated:true, completion: nil)
}
至于提交部分,我在理解数组以及向 php/ 数据库提交数组时遇到了麻烦。请帮我说一下,因为我不知道如何从这里继续。我需要提交图片数组(最多 3 张图片)以及表单中的其他参数。
@IBAction func submitAction(_ sender: Any)
{
let URL_Submit = "http://localhost/form.php"
let parameters: Parameters=[
"block":blockText.text!,
"category":catText.text!,
"description":descText.text!]
Alamofire.request(URL_Submit, method: .post, parameters: parameters).responseJSON
{
response in
//printing response
print(response)
let alertController = UIAlertController(title: "Success!", message:
"Your feedback has been submitted", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}
}
我删除了我在 submitAction 中上传图片的尝试,因为它不起作用。请帮我说一下,因为我现在真的不知道继续。感谢您的宝贵时间
【问题讨论】:
-
您能告诉我,我的回答是否解决了您的问题?
标签: php arrays xcode swift3 alamofire