ios - UITableViewCell' 没有成员 'dequeueReusableCellWithIdentifier'

标签 ios swift uitableview

错误来自 let cell = self.tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell 我该如何处理这个问题,为什么会出现问题?

class ViewController: UIViewController , UITableViewDataSource {
        @IBOutlet weak var tableView: UITableViewCell!
        override func viewDidLoad() {
            super.viewDidLoad()
            }
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
        }

        func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
            return 20
        }
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            let cell = self.tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell
            return cell
        }
        }

最佳答案

您的 tableView socket 被错误地声明为 UITableViewCell 而不是 UITableView

@IBOutlet weak var tableView: UITableView!

顺便说一句 - 在各种数据源和委托(delegate)方法中,使用 tableView 参数而不是访问属性。

例子:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell
    return cell
}

关于ios - UITableViewCell' 没有成员 'dequeueReusableCellWithIdentifier',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34689502/

相关文章:

ios - 在 UITableViewCell 中使用 UIPanGestureRecognizer 的问题

ios - 数据 : <fault> issue in another function after fetching data from core data

ios - iOS View TableViewCell 中的面向对象编程问题

ios - 如何使用 Image Sets 为不同设备设置 Viewcontroller 背景图片?

ios - 无法控制单击时单元格的按钮图像变化

swift - 如何在 Swift 中导入 bugsense

iOS 无法删除通知观察器。 Deinit 没有被调用

objective-c - UIViewController 未调用 viewDidLoad 且未创建 UIView 导致崩溃

ios - 下面的代码是否有潜在的内存泄漏?

iphone - 如何从 URL 中捕获所需的值