배열에서 데이터를받지 쿼리의 for 루프에서 모든 값을 적절한 배열로 가져옵니다. 그러나이 정보를 사용하여 내 컬렉션보기를 채울 때 아무 일도 일어나지 않습니다. 수동으로 생성 된 배열 tableImages 및 tableData에 대해 테스트를 위해 주석 처리했기 때문에이 문제를 파악할 수 없습니다.indexPath.row 내가 배열의 값을 인쇄 할 경우 배열</p> <pre><code>var packsAvailable = [""] var packsImage = [""] var packsDescription = [""] </code></pre> <p>의 몇 내 구문 분석 서버와 풋에서이 일부 문자열을 얻을 수있는 <code>PFQuery</code>을 만든
import UIKit
import Parse
private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController {
//var tableData: [String] = ["Tis is a description", "Test 22", "Test 33"]
//var tableImages: [String] = ["walk1bg", "2", "walk3bg"]
var packsAvailable = [""] // the total packs in the app
var packsImage = [""]
var packsDescription = [""]
override func viewDidLoad() {
super.viewDidLoad()
let packQuery = PFQuery(className: "Pack")
packQuery.findObjectsInBackground(block: { (objectsArray, error) in
if error != nil {
print(error!)
} else if let packs = objectsArray {
self.packsAvailable.removeAll() // remove them incase they double up
print(packs.count)
for object in packs {
/*
print(object["packName"])
print(object["packImage"])
print(object["packDesctription"])
*/
self.packsAvailable.append(object["packName"] as! String)
self.packsImage.append(object["packImage"] as! String)
self.packsDescription.append(object["packDesctription"] as! String)
/*
print(self.packsAvailable)
print(self.packsImage)
print(self.packsDescription)
*/
}
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: UICollectionViewDataSource
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return packsAvailable.count
}
func UIColorFromHEX(hexValue: UInt) -> UIColor {
return UIColor(
red: CGFloat((hexValue & 0xFF0000) >> 16)/255.0,
green: CGFloat((hexValue & 0x00FF00) >> 8)/255.0,
blue: CGFloat(hexValue & 0x0000FF)/255.0,
alpha: CGFloat(1.0)
)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: CollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CollectionViewCell
//cell.labelCell.text = tableData[indexPath.row]
//cell.imageCell.image = UIImage(named: tableImages[indexPath.row])
cell.labelCell.text = packsDescription[indexPath.row]
print(packsDescription[indexPath.row])
cell.imageCell.image = UIImage(named: packsImage[indexPath.row])
cell.imageCell.layer.masksToBounds = true
cell.imageCell.layer.cornerRadius = cell.imageCell.frame.height/2
cell.imageCell.layer.borderWidth = 3
cell.imageCell.layer.borderColor = UIColorFromHEX(hexValue: 0x62aca2).cgColor
return cell
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Selected \(indexPath.row)")
}
}
안녕하세요이 같은 시도 http://stackoverflow.com/questions/29812422/swift-converting-pfquery-to-string-array-for-tableview –
HTTP 완료 후
collectionView.reloadData()
추가 //stackoverflow.com/questions/30227511/swift-1-2-and-parse-issue-with-retrieving-images-to-populate-pfquerycollectionv –