我正在关注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.这里没什么可做的.这可能是个错误吗?
| 归档时间: |
|
| 查看次数: |
1416 次 |
| 最近记录: |