哪种是符合UITableView协议的好方法?

Hem*_*ang 0 uitableview ios swift

我遵循指南来实施UITableView协议.但是现在,它给我一个错误,我做错了什么?

'RequestsViewController'不符合协议'UITableViewDataSource'.


class RequestsViewController: UIViewController {
    ...
    ...
}

extension RequestsViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arrayRequests.count
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> RequestsTableViewCell {
        let cell:RequestsTableViewCell = (tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as! RequestsTableViewCell)
        //Doing some assignments.
        return cell
    }
}

extension RequestsViewController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    }
}
Run Code Online (Sandbox Code Playgroud)

aas*_*sya 6

改变这一点

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> RequestsTableViewCell
Run Code Online (Sandbox Code Playgroud)

至:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
Run Code Online (Sandbox Code Playgroud)

  • 基本上,你正在确认一个协议,在`UITableViewDataSource`中该方法返回`UITableViewCell`.通过改变方法改变.因此,实际方法永远不会得到确认. (2认同)