swift - iOS App screen freezes when loading more than 2 collection views inside container view -
i have viewcontroller has 4 containers. intent fill containers 4 collectionviews defined on separate viewcontroller. but, problem is, when 4 collection views loaded, cannot app. no buttons nor scrolling happens. freezes- no errors thrown. when load 2 of collection views works fine. idea why happens?
here code:
import uikit class homeviewcontroller: uiviewcontroller { @iboutlet weak var newproductscontainer: uiview! @iboutlet weak var featuredproductscontainer: uiview! @iboutlet weak var packagelistcontainer: uiview! @iboutlet weak var productccontainer: uiview! @iboutlet weak var discountcontainer: uiview! override func viewdidload() { super.viewdidload() self.createslideshow() self.setnewproductscontainercontent() self.setfeaturedcontainercontent() self.setpackagelistcontainercontent() print("hello there") } func setnewproductscontainercontent(){ let productcollectionvc: productcollectionviewcontroller = storyboard?.instantiateviewcontrollerwithidentifier("productcollection") as! productcollectionviewcontroller productcollectionvc.collectiontype = "new_products" self.newproductscontainer.addsubview(productcollectionvc.view) self.addchildviewcontroller(productcollectionvc) } func setfeaturedcontainercontent(){ let productcollectionvc: productcollectionviewcontroller = storyboard?.instantiateviewcontrollerwithidentifier("productcollection") as! productcollectionviewcontroller productcollectionvc.collectiontype = "new_products" self.featuredproductscontainer.addsubview(productcollectionvc.view) self.addchildviewcontroller(productcollectionvc) } func setpackagelistcontainercontent(){ let productcollectionvc: productcollectionviewcontroller = storyboard?.instantiateviewcontrollerwithidentifier("productcollection") as! productcollectionviewcontroller productcollectionvc.collectiontype = "new_products" self.packagelistcontainer.addsubview(productcollectionvc.view) self.addchildviewcontroller(productcollectionvc) } override func didreceivememorywarning() { super.didreceivememorywarning() print("memory warning") } }
hello there printed without problem.
productcollectionviewcontroller
import uikit import kvnprogress import objectmapper import kingfisher class productcollectionviewcontroller: uiviewcontroller, uicollectionviewdatasource, uicollectionviewdelegate { @iboutlet weak var productcoll: uicollectionview! var collectiontype: string = "all_products" var products: [product] = [] override func viewdidload() { super.viewdidload() self.productcoll.datasource = self self.productcoll.delegate = self self.initialize() } func initialize() { kvnprogress.show() serviceprovider.getproductsbylimit(0, limit: 10){ (products: [product]) in kvnprogress.dismiss() self.products = products self.productcoll.reloaddata() } } override func didreceivememorywarning() { super.didreceivememorywarning() } func numberofsectionsincollectionview(collectionview: uicollectionview) -> int { return 1 } func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int { return products.count } func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { let cell = collectionview.dequeuereusablecellwithreuseidentifier("procell",forindexpath:indexpath) as! procell let product: product = products[indexpath.row] cell.title.text = product.title var prices:[prices] = product.prices var price = "" if prices.count > 0 { price = string(prices[0].retailprice) } cell.price.text = price var pictures: [picture] = product.pictures print(pictures.count) if pictures.count > 0 { cell.image.kf_setimagewithurl(nsurl(string: constants.fineurl+"mallbackoffice/resources/images/product/general/"+pictures[0].name)!) } return cell } func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath) { print("clicked") } }
getproductsbylimit method uses alamofire fetch data fetched without problem.
Comments
Post a Comment