iOS : 'MyViewController' does not conform to protocol 'UITableViewDataSource'

后端 未结 4 2185
广开言路
广开言路 2020-12-29 05:43
  • I am new to IOS swift development. I used to work with previous Xcode 6 beta.

  • I have downloaded the Xco

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 06:31

    Try this simple solution:

    import UIKit
    
    class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
    {
        //MARK: - Life Cycle
        override func viewDidLoad() {
            super.viewDidLoad()
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
        }
    
        //MARK: - Tableview Delegate & Datasource
        func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int
        {
            return 10
        }
    
        func numberOfSectionsInTableView(tableView: UITableView) -> Int
        {
            return 1
        }
    
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
        {
    
            let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
            return cell
        }
    
        func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
        {
    
        }
    
    }
    

提交回复
热议问题