【问题标题】:Swift Error type 'usersVC' does not conform to protocol 'UITableViewDataSource'Swift 错误类型“usersVC”不符合协议“UITableViewDataSource”
【发布时间】:2015-05-24 07:12:23
【问题描述】:

我的代码不断出现编译错误。我不确定发生了什么。请帮忙!我曾尝试查看所有其他论坛,但没有任何帮助。如果这很重要,我正在为我的项目使用解析...

//
//  usersVC.swift
//  CaastRun
//
//  Created by Computer on 5/23/15.
//  Copyright (c) 2015 Caast. All rights reserved.
//

import UIKit

class usersVC: UIViewController, UITableViewDataSource, UITableViewDelegate {


    @IBOutlet weak var resultsTable: UITableView!
    var resultsNameArray = [String]()
    var resultsUserNameArray = [String]()
    var resultsImageFiles = [PFFile]()

    override func viewDidLoad() {
        super.viewDidLoad()


    let theWidth = view.frame.size.width
        let theHeight = view.frame.size.height

        resultsTable.frame = CGRectMake(0, 0, theWidth, theHeight)


    }

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

    func tableview(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return resultsNameArray.count

    }

    func tableview(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 64
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell:usersCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! usersCell

        return cell

    }
}

【问题讨论】:

  • 错别字:tableview 应该是 tableView,大写 V。 – 由于一个简单的印刷错误,投票结束。

标签: ios xcode swift parse-platform


【解决方案1】:

正如 Martin R 所说,这部分代码需要 tableView 中的“V”大写:

改变这个:

   func tableview(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return resultsNameArray.count

    }

到这里:

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

        return resultsNameArray.count

    }

【讨论】:

  • override 仅在 UITableViewController 的子类中的方法,但 OP 有 UIViewController 的子类 ...这些是 UITableViewDataSource 方法,而不是 @ 987654326@ 方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多