in controller, parse data json array , use populate collection view. code below loads , displays data, fails create individual sections.
as such, how modify code create sections each object within array. example, if array has count of 50 urls, how create 1 section each?
let lastitem = self.photos.count self.photos.addobjectsfromarray(photoinfos) let indexpaths = (lastitem..<self.photos.count).map { nsindexpath(foritem: $0, insection: 0) } dispatch_async(dispatch_get_main_queue()) { self.collectionview!.insertitemsatindexpaths(indexpaths) }
most of time apps use 1 section , many items in section that's why may bit harder find how way.
it's how use 2 functions of datasource:
func numberofsectionsincollectionview(collectionview: uicollectionview) -> int { return self.items.count } func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int { return 1 }
normally return 1 section , array count in numberofitemsinsection, if switch them have want.