我不能让我的代码正常工作,它总是说“UITableView!,numberOfRowsInSection:int)->int'没有名为'dequeueReusableCellWithIdentifier'的成员
如果有人能解释一下,我会很高兴的:)
这是我的swift文件:
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)
}
最佳答案
调用dequeueReusableCellWithIdentifier
时使用了错误的变量:
secondTableView.dequeueReusableCellWithIdentifier("Cell") as SecondCustomCellTableViewCell
secondTableView
是函数指针。相反,您希望使用传递给函数的
tableView
:tableView.dequeueReusableCellWithIdentifier("Cell") as SecondCustomCellTableViewCell