2017-12-05 9 views
1

私はJsonを解析し、それをテーブルビューのセルの中にあるコレクションビューアイテムとして表示しようとしています。だから、階層は次のようになります: - > TableViewCell - > CollectionView -TableViewCell内のCollectionViewCellにJsonを表示します。 Swift 3

MainTableVIew> CollectionViewCell

だから私は、JSON、私はそれを解析され

"payments":[{ 
    "type":"card", 
    "title":"Card" 
}, { 
    "type":"sms", 
    "title":"SMS", 
    "max_amount":24 
},{ 
    "type":"account", 
    "title":"Account", 
    "disabled":true, 
    "max_amount":-1 
}] 

を持っています。私は 次のことは

var package : PromoPayment? { 
     didSet { 
      collectionView.reloadData() 
     } 
    } 

であると私は辞書を取得するクラスをPromoPaymentどのパッケージ

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
      let cell = tableView.dequeueReusableCell(withIdentifier: "NewPaymentCell") as! NewPaymentTableViewCell 
      cell.package?.title = payments[indexPath.row].title 
      return cell} 

です。 NewPaymentCollectionViewクラスで

私はまたのような細胞を移入:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NewPaymentCollectionCell", for: indexPath) as! NewPaymentCollectionViewCell 
     cell.paymentIcon.image = UIImage(named: iconImage[indexPath.row]) 
     cell.kidPayment?.title = (package?.title)! 
     return cell 
    } 
kidPaymentが

var kidPayment : PromoPayment? { 
    didSet{ 
     namePaymentTypeLabel.text = kidPayment?.title 
     } 
    } 

であると私はそれは私にnilを返すデバッグする場合、それはクラスでNewPaymentCollectionViewCell: UICollectionViewCell

をモデル化sの

..

あなたのHを気に入ってくださいエル・P。

答えて

0

これは、テーブルビューのカスタムセルをデザインし、その内部にコレクションビューを追加することで試すことができます。コレクションビューのコンセントを作成し、コレクションビューを指定されたコードごとに再ロードしてみます。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
      let cell = tableView.dequeueReusableCell(withIdentifier: "NewPaymentCell") as! NewPaymentTableViewCell 
      cell.package?.title = payments[indexPath.row].title 
      **cell.collectionView.reloadData()** 
      return cell 
} 

didsetメソッドを使用する代わりに、これを使用します。

+0

ご協力ありがとうございます。私は、costumセルと、newPaymentCollectionViewであるcollectionViewクラスも持っています。私はあなたが言ったが何もしなかった。私はCollectionViewCellにデバッグを入れて、それを取得することもありません。 –

+0

コレクションビューのデリゲートとデータソースをプログラマチックに、コレクションビューを再ロードする直前に設定します。 –

関連する問題