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")
}
}
}斯威夫特约视图不确认议定书“UITableViewDataSource”
这是我的程序的代码,我试图做一个待办事项列表应用程序,但错误没有确认到协议“UITableViewDataSource”总是出现,我试图找到解决方案,但没有适合我的,任何人都可以帮助我?谢谢
等待,这里不是必须的'override'关键字吗? – Alexander
@AlexanderMomchliov如果方法在父类中定义,则只需要“覆盖”。 'UIViewController'没有定义任何表视图方法。 – rmaddy
噢,对于协议方法实现,你不使用'override' – Alexander