Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Missing print message when clicking the cell Swift TableView

just finish a course and this is my first app that I am building, currently I am trying to create a tableView in which each cell is create by an object from a .xib file and when i try to click the cell and print the message from the cell it does nothing.

Can someone give me a hint what I am doing wrong please because I spent hours searching on the internet but I could not find the solution .

Kind regards to everyone.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

code down below :

import UIKit

class HomePageViewController : UIViewController, UITableViewDelegate,  UITableViewDataSource {
    
    
    @IBOutlet weak var menuCell: UIView!
    @IBOutlet weak var tableView: UITableView!

        
    var messages : [Message] = [
        Message(message: "Check Menu", destination: "One"),
        Message(message: "Chech order", destination: "One"),
    ]
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.separatorStyle = .none
        navigationItem.hidesBackButton = true
        tableView.dataSource = self
        tableView.register(UINib(nibName: "MenuCell", bundle: nil), forCellReuseIdentifier: "ReusableCell")
        tableView.rowHeight = 80.0
        
    }
    
    
    
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return messages.count
    }
    
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ReusableCell", for: indexPath) as! MenuCell
        cell.labelMenu?.text = messages[indexPath.row].message
        return cell
    }
    
    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        print(messages[indexPath.row].message)
    }  
}

>Solution :

I think that you’re missing tableView delegate, add it in viewDidLoad:

tableView.delegate = self
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading