1
votes

OK I saw many forums and I did not find anything concrete with the problem that I have.

  • I have a ViewController where I added a UITableView.

enter image description here

  • The UITableView loads a UITableViewCell created as xib file

enter image description here

  • The TableViewCell has a UITableView that in turn has a UITableViewCell created also as a xib file.

enter image description here

enter image description here

  • This is how load the firts UITableViewCell inside the Firts UITableView. The load in ViewController:

    tableDetails.delegate = self tableDetails.dataSource = self tableDetails.register(UITableViewCell.self, forCellReuseIdentifier: "DepartureDetailTableViewCell")

The problem is that I do not know how I'm going to load the Second UITableViewCell inside the Second UITableView in xib file from the ViewController. Any help?. And also, how do this for the Second UITableView/UITableViewCell.

enter image description here

PD.: See this tutorial, but he use prototype cell inside ViewController: https://www.youtube.com/watch?v=znGd5kyIdgM

Please Help!

UPDATE:

OK i solve the problem with @Abdelahad Darwish solution! but i have another problem...when load the DepartureInsideTableViewCell in DepartureDetailTableViewCell...not show anything... it show like this:

enter image description here

Has to show the DepartureInsideTableViewCell in the middle of the two view "May 30, 2018 - 01:04" and "May 30, 07:47"

Any help?

1
So you have UIViewController With TableView, and cell of Main TableView have another TableView with CustomCell - Abdelahad Darwish
yes...that is correct. - xhinoda

1 Answers

3
votes

First for Your MainTableView Just Register Normal Cell from Xib Just do it normal and DepartureDetailTableViewCell will have all Datasource and delegate for Inside cell Like that :

don't forget to write correct cell identifiers and so on

In ViewController :

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {


    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableView.register(UINib.init(nibName: "DepartureDetailTableViewCell", bundle: nil), forCellReuseIdentifier: "DepartureDetailsTableViewCell")
        self.tableView.delegate = self
        self.tableView.dataSource = self

    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DepartureDetailTableViewCell", for: indexPath) as! DepartureDetailTableViewCell
        return cell
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4 // cell data source
    }
}

In DepartureDetailTableViewCell:

class DepartureDetailTableViewCell: UITableViewCell {

    @IBOutlet weak var tableView:UITableView!

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

        self.tableView.register(UINib.init(nibName: "DepartureInsideTableViewCell", bundle: nil), forCellReuseIdentifier: "DepartureInsideTableViewCell")
        self.tableView.delegate = self
        self.tableView.dataSource = self
    }


}

extension DepartureDetailTableViewCell: UITableViewDelegate,UITableViewDataSource{

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DepartureInsideTableViewCell", for: indexPath) as!  DepartureInsideTableViewCell
        return cell
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4 // cell data source
    }
}