2017-02-16 11 views
1

jsonデータがnilの場合、セクションのセルコレクションビューを非表示にする方法。テーブルビューのcell.myコード中1Mローディングcollectionviewはbelowim iがコレクションビューjsonデータがnilの場合、tableviewのセルを非表示にする方法

func setCollectionData(_collectionData: [Any]) { 
    self.collectionData = _collectionData as NSArray  
    collectionViewObj.setContentOffset(CGPoint(x:0,y:0), animated: true)  
    for i in 0 ..< collectionData.count { 
     self.strings = StringClass() 
     self.strings.vehicleImage = (collectionData[i] as AnyObject).value(forKey: "img_name") as? String       
     self.strings.vehicleTitle=(collectionData[i] as AnyObject).value(forKey: "p_name") as? String     
     self.modelArray.append(self.strings)       
    }  
    collectionViewObj.reloadData() 
}    
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int 
{ 
    if self.collectionData.count >= 4 { 
     return 4 
    } 
    else 
    { 
    return collectionData.count 
    } 
}  

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell 
{ 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductCollectionViewCustomCell", for: indexPath)as! ProductCollectionViewCustomCell   
    strings = modelArray[indexPath.row]   
    cell.ProductTitleLabel.text = strings.vehicleTitle   
    let URLBaseString = "http://vehiclebuzzzz.com/"   
    let url = URL(string:URLBaseString .appending(strings.vehicleImage!))   
    let dataurl = try? Data(contentsOf: url!)  
    cell.productImageViewObj.image=UIImage(data: dataurl!)     
    return cell 
} 
+0

データソースから非表示にしたいデータを削除し、テーブルビューを再読み込みするのが最も簡単な方法です。 – Greg

+0

正確にあなたはあなたにtableview cell&your codeを求める質問をしていますか? –

+0

私はテーブルビューのセルでコレクションビューをロードしています。コレクションビューの最初のセクションにarray1をロードし、コレクションビューの2番目のセクションにarray2をロードする必要があります。 array1が空の場合、そのセクションを非表示にしたい – Naveen

答えて

0
func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath) -> CGSize 

オーバーライドこの方法のために第三者としてhorizo​​ntalautomaticスクロールするためのサードパーティを使用し、ゼロサイズを返したコレクションビューの画像の配列を示していますJSONデータが他のセルの実際のサイズを返すnilの場合CGSize.zero

ORアレイから

削除ゼロデータと呼んcollectionView.reloadData()

0

更新あなたはショーのコレクションビューを望んでいない-IF新しいデータ&とcollectionData配列は、その後collectionViewObj.reloadData()

0

を行います。データを取得するまでコレクションビューを隠すだけです。 - データを表示させるとき

関連する問題