UICollectionView를 사용하여 백엔드리스 데이터베이스에서 이미지를 다운로드하고 표시합니다. 어떻게이 이미지를 포함하고있는 ViewController에서 이미지를 다시 표시 할 수 있습니까? Swift3를 사용하여 My CollectionView의 행을 탭하면 ImageView가 표시됩니다.Swift3를 사용하여 백엔드 데이터베이스에서 ImageView를 다운로드 한 후 새 ViewController에 이미지를 표시하는 방법
이것은 내 CollectionView입니다.
import UIKit
import SDWebImage
class GallaryCollectionViewController: UICollectionViewController {
var GallaryArray = [TestTable]()
let backendless = Backendless()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
loaddatawithquery()
}
// MARK: UICollectionViewDataSource
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return GallaryArray.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? GallaryCell {
let ImgURL = URL(string : self.GallaryArray[(indexPath as NSIndexPath).row].ImgURL!)
cell.GallImag.sd_setImage(with: ImgURL)
cell.ShowImg = {
if let myimage = (cell.GallImag.image) {
// Error here How to complete the code ?
}
}
return cell
}
else {
let cell = GallaryCell()
let ImgURL = URL(string : self.GallaryArray [(indexPath as NSIndexPath).row].ImgURL)
cell.GallImag.sd_setImage(with: ImgURL)
cell.ShowImg = {
if let myimage = (cell.GallImag.image) {
}
}
return cell
}
}
func loaddatawithquery() {
let dataQuery = BackendlessDataQuery()
dataQuery.queryOptions.pageSize = 50
backendless.data.of(TestTable.ofClass()).find(dataQuery,response: {(result: BackendlessCollection?) -> Void in
let data = result?.getCurrentPage()
for obj in data! as! [TestTable] {
self.GallaryArray.append(obj)
self.collectionView?.reloadData()
}
}, error: { (fault: Fault?) -> Void in
let alert = UIAlertController(title: "انتباه", message:"يرجى الاتصال بالانترنيت", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in })
self.present(alert, animated: true){}
})
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {}
}
그리고 이것은 나의 세포입니다.
import UIKit
class GallaryCell: UICollectionViewCell {
@IBOutlet weak var GallImag: UIImageView!
var ShowImg : (() ->Void)?
func setSelected(_ selected: Bool, animated: Bool) {
setSelected(selected, animated: animated)
self.ShowImg!()
}
}
백엔드가 무엇을 의미합니까? – Honey
Backendless 데이터베이스를 사용하여 데이터를 다운로드하고 있습니다. –