没有名为dequeueReusableCellWithIdentifier的成员

时间:2015-04-04 11:21:46

标签: xcode uitableview swift cell reuseidentifier

我无法让我的代码正常工作,它一直在说" UITableView!,numberOfRowsInSection:int) - >诠释'没有名为' dequeueReusableCellWithIdentifier'" enter image description here

如果有人可以解释这个问题会很高兴。

这是我的快速文件:

import UIKit

class SecondViewController: UIViewController, UITableViewDelegate, UISearchBarDelegate {
@IBOutlet weak var mySecondTableView: UITableView!

var secondArrayOfDisplays: [secondDisplayName] = [secondDisplayName] ()

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
    self.setUpDisplays()
}

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

func setUpDisplays()
{
    var display1  = secondDisplayName(secondName: "8 Inch STD Widescreen", secondImageName: "8 Inch Widescreen.png")
    var display2  = secondDisplayName(secondName: "12 Inch MMD", secondImageName: "12 inch mmd.png")
    var display3  = secondDisplayName(secondName: "12 Inch STD", secondImageName: "12 inch std.png")
    var display4  = secondDisplayName(secondName: "13 Inch STD Widescreen", secondImageName: "13 inch std.png")
    var display5  = secondDisplayName(secondName: "15 Inch MMD", secondImageName: "15 inch mmd.png")
    var display6  = secondDisplayName(secondName: "15 Inch STD", secondImageName: "15 inch std.png")
    var display7  = secondDisplayName(secondName: "17 Inch MMD", secondImageName: "17 inch mmd.png")
    var display8  = secondDisplayName(secondName: "17 Inch STD", secondImageName: "17 inch std.png")
    var display9  = secondDisplayName(secondName: "19 Inch MMD", secondImageName: "19 inch mmd.png")
    var display10 = secondDisplayName(secondName: "19 Inch STD", secondImageName: "19 inch std.png")
    var display11 = secondDisplayName(secondName: "24 Inch MMD Widescreen", secondImageName: "24 inch mmd.png")
    var display12 = secondDisplayName(secondName: "24 Inch STD Widescreen", secondImageName: "24 inch std.png")
    var display13 = secondDisplayName(secondName: "26 Inch MMD Widescreen", secondImageName: "26 inch mmd.png")
    var display14 = secondDisplayName(secondName: "26 Inch STD Widescreen", secondImageName: "26 inch std.png")

    secondArrayOfDisplays.append(display1)
    secondArrayOfDisplays.append(display2)
    secondArrayOfDisplays.append(display3)
    secondArrayOfDisplays.append(display4)
    secondArrayOfDisplays.append(display5)
    secondArrayOfDisplays.append(display6)
    secondArrayOfDisplays.append(display7)
    secondArrayOfDisplays.append(display8)
    secondArrayOfDisplays.append(display9)
    secondArrayOfDisplays.append(display10)
    secondArrayOfDisplays.append(display11)
    secondArrayOfDisplays.append(display12)
    secondArrayOfDisplays.append(display13)
    secondArrayOfDisplays.append(display14)
}

func secondTableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
{
    return secondArrayOfDisplays.count
}

func secondTableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
    let secondCell: SecondCustomCellTableViewCell =
    secondTableView.dequeueReusableCellWithIdentifier("Cell") as SecondCustomCellTableViewCell

    let secondDisplay = secondArrayOfDisplays[indexPath.row]
    secondCell.setSecondCell(secondDisplay.secondName, imageName: secondDisplay.secondImageName)

    secondCell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

    return secondCell
}

func secondTableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
    let secondDisplay = secondArrayOfDisplays[indexPath.row]

    var SecondDetailedViewController: SecondDetailViewController = self.storyboard?.instantiateViewControllerWithIdentifier("SecondDetailViewController") as SecondDetailViewController

    SecondDetailedViewController.secondNameString = secondDisplay.secondName
    SecondDetailedViewController.mySecondDetailedImageName = secondDisplay.secondImageName

    self.presentViewController(SecondDetailedViewController, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:2)

当您致电dequeueReusableCellWithIdentifier时,您使用了错误的变量:

secondTableView.dequeueReusableCellWithIdentifier("Cell") as SecondCustomCellTableViewCell

secondTableView是一个函数指针。

相反,您希望使用传递给函数的tableView

tableView.dequeueReusableCellWithIdentifier("Cell") as SecondCustomCellTableViewCell