2017-10-07 1 views
0

두 개의 사용자 지정 셀이있는 UICollection보기가 있습니다. UICollectionViewCell 사용자 정의 셀은 NIB를 사용하여 작성됩니다. 하나의 UICollectionViewCell 콧노래 안에는 UITableView가 있습니다. 그러나 UITableView 자체에는 사용자 지정 셀이 있습니다. 그래서 내 질문은 :이미 NIB 인 UICollectionViewCell 내부에서 사용자 지정 셀로 UITable을로드하는 방법

UICableViewCell NIB 대신 UITableView에 대한 사용자 지정 셀을로드하려면 어떻게해야합니까? 거의 모든 경우에

import UIKit 

class HeaderFooterCollectionViewCell: UICollectionViewCell { 

    //Tableview 
    @IBOutlet weak var tableView: UITableView! 

    //Buttons 
    @IBOutlet weak var resetButton: UIButton! 
    @IBOutlet weak var periodButton: UIButton! 
    @IBOutlet weak var undoButton: UIButton! 


    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 

     // Register cell classes 
     tableView.register(UINib(nibName: "ShotInformationTableViewCell", bundle: nil), forCellReuseIdentifier: "cell") 
    } 

} 

extension HeaderFooterCollectionViewCell: UITableViewDataSource { 

    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ShotInformationTableViewCell 

     return cell 
    } 
} 

답변

1
let cell = Bundle.main.loadNibNamed("XIB_File_Name", owner: self, options: nil)?.first as! XIB_Class_Name 

, 응답 @Roy에 대한 XIB_File_Name == XIB_Class_Name

+0

감사합니다. 그게 효과가 있었어. –

+0

안녕하세요. 나는'cellForItem'을 반환하는 동안 내 대답을 사용하고 있지만 불행히도'let cell = UINib (nibName : "XIB_File_Name", 번들 : nil) .instantiate (withOwner : nil, options : nil) [0] XIB_Class_Name' 결과가 동일하므로 내 대답이 어떻게 효과가 있었습니까? – Roy

+0

이것은 내 코드'let cell = Bundle.main.loadNibNamed ("ShotInformationTableViewCell", owner : self, options : nil)입니까? ShotInformationTableViewCell' 제대로 작동합니다. –

관련 문제