在Swift中没有确认协议UITableViewDataSource,为什么? [英] does not confirm to protocol UITableViewDataSource in Swift , Why?
本文介绍了在Swift中没有确认协议UITableViewDataSource,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,编译器仍然显示错误,虽然我编写了两种方法的实现
Here is my Code , Compiler is still showing error although I wrote implementation of both methods
请说明原因
import UIKit
import UIKit
class FirstViewController: UIViewController , UITableViewDelegate, UITableViewDataSource {
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 taskMgr.tasks.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell : UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "test")
cell.textLabel?.text = taskMgr.tasks[indexPath.row].name
cell.detailTextLabel?.text = taskMgr.tasks[indexPath.row].desc
return cell
}
}
以下是Xcode的截图
Here is screenshot of Xcode
推荐答案
您可能已在先前版本的Xcode中编写此代码。 2种方法的正确签名已经改变,现在是:
You have probably written this code in a previous version of Xcode. The correct signature for the 2 methods has changed, and it's now:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
tableView
参数不再一个可选的。
The tableView
parameter is no longer an optional.
这篇关于在Swift中没有确认协议UITableViewDataSource,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文