lundi 2 mai 2016

Can't create a tableview checkmarks inside a tableviewController swift 2

I want to create a tableview inside a tableViewController to create a "checkbox group" components like in this tutorial :

http://ift.tt/1P38xfi

So I create a custom cell to implement this "checkbox group" but the data is not display inside it, the function tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell is not called and I supposed it's because I don"t refer my tableview with the datasource and delegate but I don't know how to do that because it's a tableview inside a tableview controller.

How can I solved this problem ?

import UIKit

class FirstCustomCell: UITableViewCell, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var answersTableView: UITableView!


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

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }


    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        print("section")
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print("row")
        return 4
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        print("cell answer") // never called
        let cell = tableView.dequeueReusableCellWithIdentifier("CheckBoxAnswer", forIndexPath: indexPath) as! SingleChoiceCellAnswer
        cell.answerLabel.text = "test"
        cell.selectionStyle = UITableViewCellSelectionStyle.None
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 160.0
        return cell
    }

    // Mark: Table View Delegate

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    }

}

Here it's my custom cell for the possible answers :

import UIKit

class SingleChoiceCellAnswer: UITableViewCell {

    @IBOutlet weak var answerLabel: UILabel!

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

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}




Aucun commentaire:

Enregistrer un commentaire