gpt4 book ai didi

ios - Swift about view 不符合协议(protocol) "UITableViewDataSource"

转载 作者:行者123 更新时间:2023-11-28 16:06:39 25 4
gpt4 key购买 nike

class showPageViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {


var records : [Record] = []
@IBOutlet weak var tableView: UITableView!



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 numberOfSections(in tableView: UITableView) -> Int {
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return records.count
}

func tableview(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

return UITableViewCell()


}

func tableView(_ tableVoew: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath){
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

if editingStyle == .delete{
let record = records[indexPath.row]
context.delete(record)
(UIApplication.shared.delegate as! AppDelegate).saveContext()
do{
records = try context.fetch(Record.fetchRequest())
} catch{
print("Failed")
}
}


}

override func viewWillAppear(_ animated: Bool) {
getData()
tableView.reloadData()
}

func getData(){
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
do{
records = try context.fetch(Record.fetchRequest())
} catch{
print("123")
}
}

这是我的程序代码,我正在尝试制作一个待办事项列表应用程序,但错误并没有确认协议(protocol)“UITableViewDataSource”总是出现,我试图找到解决方案,但没有适合我的,有人可以帮助我吗?谢谢

最佳答案

您的代码中混合使用了 Swift 2 和 Swift 3 方法。您的 cellForRow... 方法使用较新的 Swift 3 签名。您需要使用旧的 Swift 2 兼容版本。

我认为是:

func tableview(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
}

检查所有其他 TableView 数据源和委托(delegate)方法,并确保它们都使用 Swift 2 兼容签名而不是较新的 Swift 3 签名。

关于ios - Swift about view 不符合协议(protocol) "UITableViewDataSource",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40188824/

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