gpt4 book ai didi

ios - ViewController 不确认协议(protocol) UITableViewDataSource

转载 作者:行者123 更新时间:2023-11-29 02:36:51 26 4
gpt4 key购买 nike

我做的很好但仍然显示错误“ViewController does not confirm to protocol”我在这个网站上搜索了很多,我发现了同样的问题,但没有找到任何正确答案我已经将 UITableView 的连接添加到 UITableViewDelegate 和 UITableViewDataSource,但仍然显示错误我该怎么办

这是我的代码

class ViewController: 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.
}

@IBOutlet var tableView: UITableView!


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

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

let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
cell.textLabel.text="row#\(indexPath.row)"
cell.detailTextLabel.text="subtitle#\(indexPath.row)"

return cell

}



}

最佳答案

请注意删除委托(delegate)方法中的 !,这是错误的。

class ViewController: 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.
}

@IBOutlet var tableView: UITableView!


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

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

let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
cell.textLabel.text="row#\(indexPath.row)"
cell.detailTextLabel.text="subtitle#\(indexPath.row)"

return cell

}



}

关于ios - ViewController 不确认协议(protocol) UITableViewDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26255099/

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