如果我使用自定义单元格 BaseCell
,则无法导入 UITableViewDataSource。仅适用于 UITableViewCell
尽管 BaseCell
来自类型 UITableViewCell
import UIKit
class XptoViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> BaseCell {
let cell = BaseCell()
return cell
}
最佳答案
尝试相反的方法:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = BaseCell()
return cell
}
但你可能想使用类似的东西:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("BaseCell") as? BaseCell
return cell!
}
关于ios - 无法将 UITableViewDataSource 与自定义单元格一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43326701/