sách gpt4 ăn đã đi

ios - 类型 'ViewController' 不符合协议(protocol) 'UITableViewDataSource'

In lại 作者:IT王子 更新时间:2023-10-29 04:59:29 29 4
mua khóa gpt4 giày nike

开始练习swift。在 singleViewController 中,我试图制作一个 UITableView。在 Storyboard 中,我设置了数据源和委托(delegate)。在这里我收到错误 * 'ViewController' does not conform to protocol 'UITableViewDataSource' *

Screenshot for error

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var table: UITableView!


ghi đè hàm viewDidLoad() {
siêu.viewDidLoad()
// Thực hiện bất kỳ thiết lập bổ sung nào sau khi tải chế độ xem, thường là từ một nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

func numberOfSectionsInTableView(tableView: UITableView!) -> 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

}

câu trả lời hay nhất

您应该在最后一个 之前实现所有必需的方法,但是您已经在 UIViewController 之外编写了它们。此外,您需要更改行数的函数。

建议的修改

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var table: UITableView!


ghi đè hàm viewDidLoad() {
siêu.viewDidLoad()
// Thực hiện bất kỳ thiết lập bổ sung nào sau khi tải chế độ xem, thường là từ một nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

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/25581780/

29 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress