Arrays Swift TableView使用parse将图像数组发送到collectionView
这是我在这里的第一篇帖子,我在swift上开发了几个月,但我无法解决这个问题 我试着用我的形象来解释我需要帮助什么 如果我点击tableview第1行,我想发送一个包含30-70个图像的数组到一个集合视图,这种方式可以工作,除了它在所有行上显示相同的图像,tableview第2-3-4行。 请查看我的解析数据库的链接 我非常乐意与大家分享bitbucketArrays Swift TableView使用parse将图像数组发送到collectionView,arrays,swift,parse-platform,Arrays,Swift,Parse Platform,这是我在这里的第一篇帖子,我在swift上开发了几个月,但我无法解决这个问题 我试着用我的形象来解释我需要帮助什么 如果我点击tableview第1行,我想发送一个包含30-70个图像的数组到一个集合视图,这种方式可以工作,除了它在所有行上显示相同的图像,tableview第2-3-4行。 请查看我的解析数据库的链接 我非常乐意与大家分享bitbucket 类TableViewController:PFQueryTableViewController{ var selectedRow:PF
类TableViewController:PFQueryTableViewController{
var selectedRow:PFUser?
var userids = [""]
var wonk = ["wonk"]
var slagtHuset = ["slagtHuset"]
var Adelgatan = ["Adelgatan"]
// Initialise the PFQueryTable tableview
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
// Configure the PFQueryTableView
self.parseClassName = "crowd"
self.textKey = "cellTitle"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
//self.objectsPerPage=3
}
//NSIndexPath*indexPath=[self.tableView indexPathForSelectedRow];
//狗详细信息=(狗)segue.destinationViewController
//PFObject*object=[self.typeDog objectAtIndex:indexath.row];
//stringdata=[objectobjectforkey:@“username”]
//details.array=
}
}
override func viewDidAppear(animated: Bool) {
// Refresh the table to ensure any data changes are displayed
tableView.reloadData()
}
下面是detailView(collectionView)的代码
var国家=PFObject 类DetailViewController:UIViewController、UICollectionViewDataSource、UICollectionViewDelegate{
// Container to store the view table selected object
var currentObject : PFObject?
var wonk = ["wonk"]
var slagtHuset = ["slagtHuset"]
var Adelgatan = ["Adelgatan"]
//var俱乐部=[Slagthustet、Adelgatan、wonk]
// Some text fields
@IBOutlet var collectionView: UICollectionView!
@IBOutlet weak var flag: PFImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Resize size of collection view items in grid so that we achieve 3 boxes across
let cellWidth = ((UIScreen.mainScreen().bounds.width) - 3 - 3 ) / 2
let cellHeight = ((UIScreen.mainScreen().bounds.width) - 4 - 3 ) / 2
let cellLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
cellLayout.itemSize = CGSize(width: cellWidth, height: cellHeight)
}
func loadCollectionViewData() {
// Build a parse query object
var query = PFQuery(className:"crowd")
//more specs query.whereKey("currencyCode", equalTo:"EUR")
query.orderByAscending("objectId")
// Fetch data from the parse platform
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
// The find succeeded now rocess the found objects into the countries array
if error == nil {
// Clear existing country data
countries.removeAll(keepCapacity: true)
// Add country objects to our array
if let objects = objects as? [PFObject] {
countries = Array(objects.generate())
}
// reload our data into the collection view
self.collectionView.reloadData()
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(countries)
return countries.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
// Display "initial" flag image
var initialThumbnail = UIImage(named: "question")
cell.cellImage.image = initialThumbnail
// Here is my problem where i only load image from Adelgatan
// Fetch final flag image - if it exists
if let value = countries[indexPath.row]["Adelgatan"] as? PFFile {
let finalImage = countries[indexPath.row]["Adelgatan"] as? PFFile
finalImage!.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
cell.cellImage.image = UIImage(data:imageData)
}
}
}
}
return cell
// pass whatever data you want to display in the collection view as an array here.
}
}
override func viewDidAppear(animated: Bool) {
// Refresh the table to ensure any data changes are displayed
tableView.reloadData()
}
import UIKit
// Container to store the view table selected object
var currentObject : PFObject?
var wonk = ["wonk"]
var slagtHuset = ["slagtHuset"]
var Adelgatan = ["Adelgatan"]
// Some text fields
@IBOutlet var collectionView: UICollectionView!
@IBOutlet weak var flag: PFImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Resize size of collection view items in grid so that we achieve 3 boxes across
let cellWidth = ((UIScreen.mainScreen().bounds.width) - 3 - 3 ) / 2
let cellHeight = ((UIScreen.mainScreen().bounds.width) - 4 - 3 ) / 2
let cellLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
cellLayout.itemSize = CGSize(width: cellWidth, height: cellHeight)
}
func loadCollectionViewData() {
// Build a parse query object
var query = PFQuery(className:"crowd")
//more specs query.whereKey("currencyCode", equalTo:"EUR")
query.orderByAscending("objectId")
// Fetch data from the parse platform
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
// The find succeeded now rocess the found objects into the countries array
if error == nil {
// Clear existing country data
countries.removeAll(keepCapacity: true)
// Add country objects to our array
if let objects = objects as? [PFObject] {
countries = Array(objects.generate())
}
// reload our data into the collection view
self.collectionView.reloadData()
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(countries)
return countries.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
// Display "initial" flag image
var initialThumbnail = UIImage(named: "question")
cell.cellImage.image = initialThumbnail
// Here is my problem where i only load image from Adelgatan
// Fetch final flag image - if it exists
if let value = countries[indexPath.row]["Adelgatan"] as? PFFile {
let finalImage = countries[indexPath.row]["Adelgatan"] as? PFFile
finalImage!.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
cell.cellImage.image = UIImage(data:imageData)
}
}
}
}
return cell