Type 'ViewController' does not conform to protocol 'UITableViewDataSource'

后端 未结 17 2607
旧巷少年郎
旧巷少年郎 2020-11-29 03:02

Started practice swift. In singleViewController I am trying to make a UITableView. In storyboard I set the datasource and delegate. Here I am getting the error

17条回答
  •  盖世英雄少女心
    2020-11-29 03:16

    The following code didn't work for me on iOS 8.1. in XCode 6.1.1. This code works:

    import UIKit
    
    class ViewController : UIViewController,UITableViewDelegate,UITableViewDataSource {
    
        override func viewDidLoad() {
            super.viewDidLoad()
        }
    
        func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
            //currently only a testing number
            return 25
        }
    
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
    
            var cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
            cell.textLabel?.text = "row#\(indexPath.row)"
            cell.detailTextLabel?.text = "subtitle#\(indexPath.row)"
            return cell
        }
    
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    }
    

提交回复
热议问题