gpt4 book ai didi

ios - 与 "Type ' ViewController' 相关的编译和构建错误不符合协议(protocol) 'UITableViewDataSource' ”

转载 作者:行者123 更新时间:2023-11-30 12:52:01 25 4
gpt4 key购买 nike

我不明白为什么我的应用程序无法编译。这是当前的输出:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var IndexArray = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
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 numberOfSectionsinTableView(tableView: UITableView) -> Int {
return IndexArray.count
}

func tableView(tableView: UITableView, tiltleForHeaderInSection section: Int) -> String? {
return IndexArray[section]
}

func sectionIndexTitlesfortableView (tableView: UITableView) -> [String]? {
return IndexArray
}

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableCell", for: indexPath as IndexPath) as! TableCell

cell.imgPhoto.image = UIImage(named: "charity")
cell.lblUserName.text! = "User Name"

return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

}
}

最佳答案

您缺少指定在您的类派生的协议(protocol)中声明的一些方法。

func tableView(UITableView, cellForRowAt: IndexPath)必需的。请求数据源将单元格插入表格 View 的特定位置。

func tableView(UITableView, numberOfRowsInSection: Int)必需的。告诉数据源返回 TableView 给定部分中的行数。

至少必须在类中声明上述两个方法,否则会出现错误。

这些只是必需的方法,但为了以正确的方式运行,您需要定义其他方法。请参阅有关 UITableViewDataSource 协议(protocol)的 Apple 文档

关于ios - 与 "Type ' ViewController' 相关的编译和构建错误不符合协议(protocol) 'UITableViewDataSource' ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40851672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com