Swift - 添加UITableView协议

Obj*_*ift 1 swift ios8

我正在关注Apple文档(页面链接)以在空的ViewController.swift文件中添加tableview.添加协议时如下所示:

Class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// define the class
 override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
}

func tableView(tableView: UITableView!, numberOfRowsInSection section:    Int) -> Int {
return 10
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) ->        UITableViewCell! {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")

cell.text = "Row #\(indexPath.row)"
cell.detailTextLabel.text = "Subtitle #\(indexPath.row)"

return cell
}
Run Code Online (Sandbox Code Playgroud)

我收到错误:"类型ViewController不确认协议UITableViewDataSource.这里没什么可做的.这可能是个错误吗?

Fel*_*lix 5

2个必需的函数不在类定义中.只需将类的右括号移动到文件末尾即可.