xhinoda
xhinoda

Reputation: 1068

Load UITableViewCell to UITableView in xib file

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

enter image description here

enter image description here

enter image description here

enter image description here

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?

Upvotes: 2

Views: 2851

Answers (1)

Abdelahad Darwish
Abdelahad Darwish

Reputation: 6067

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
    }
}

Upvotes: 4

Related Questions