Swift: Table view superclass error

后端 未结 4 1395
我寻月下人不归
我寻月下人不归 2021-01-15 21:00

I have created a slide out menu using Swift. I have done this many times before, but when I created it today, I get this error (see screenshot). It could just be a simple mi

4条回答
  •  一向
    一向 (楼主)
    2021-01-15 21:08

    See this works for me

    • Just confirm UITableViewDelegate and UITableViewDataSource
    • Implement required methods

    import UIKit
    
    class ListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource  {
    
        let containArray = ["One","two","three","four","five"]
    
    
        // MARK: - View Lifecycle
        override func viewDidLoad() {
            super.viewDidLoad()
        }
        override func viewWillAppear(animated: Bool) {
            super.viewWillAppear(animated)
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
        //MARK: Table view data source and delegate methods
    
        //Number of rows
        func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return containArray.count
        }
    
        //Prepare Custom Cell
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
    
            let identifier = "simpleTextCell"
            var cell: SimpleTextCell! = tableView.dequeueReusableCellWithIdentifier(identifier) as? SimpleTextCell
    
            if cell == nil {
                tableView.registerNib(UINib(nibName: "SimpleTextCell", bundle: nil), forCellReuseIdentifier: identifier)
                cell = tableView.dequeueReusableCellWithIdentifier(identifier) as? SimpleTextCell
            }
    
            let dayName = containArray[indexPath.row]
            cell.lblProductName.text = dayName
    
    
            return cell
        }
    
        //Handle click
        func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            self.performSegueWithIdentifier("productListSegue", sender: self)
        }
    }
    

提交回复
热议问题