我已经开始了我的第一个应用程序,并且我希望应用程序具有作为待办事项列表的视图,但是,我得到类型'ThirdViewController'不符合协议UITableViewDataSource作为我的代码中的错误。我已经看了一个类似的线程,但没有找到解决办法有类型'ThirdViewController'不符合协议UITableViewDataSource
import UIKit
class ThirdViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
{
var list = ["Math Homework", "English Project", "Bio Quiz"]
@IBOutlet weak var myTableView: UITableView!
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return list.count
}
public func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "cell")
cell.textLabel?.text = list[indexPath.row]
return cell
}
}
清除了错误,但现在我得到了“使用未声明的类型'IndexPath'。我该如何解决这个问题? –
您在哪一行收到错误?另外,'indexPath'应该以小写字母'i '。 – vitormm
func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) - > UITableViewCell - 在你的两个建议编辑中我得到了同样的错误 –