2015-08-12 6 views
2

У меня возникает странная ошибка при попытке настроить ячейку прототипа для использования с несколькими массивами. Я создал контроллер табличного представления, который управляется «BDTableViewController» и содержит одну ячейку прототипа, которая управляется классом «BDTableViewCell». Однако Xcode жалуется, что«UITableViewCell» не имеет члена с именем «businessLabel»

«UITableViewCell» не имеет элемент с именем «businessLabel»

когда розетка businessLabel четко связана с моей BDTableViewCell. Включены сами файлы. Любая идея о том, что происходит не так?

BDTableViewController:

import UIKit 

class BDTableViewController: UITableViewController, UITableViewDelegate { 


var BusinessNameArray = [String]() 
var BusinessLogoArray = [String]() 
var BusinessAddressArray = [String]() 
var BusinessNumberArray = [String]() 
var BusinessWebsiteArray = [String]() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    BusinessNameArray = ["Premiere Dance"] 
    BusinessLogoArray = ["PD.tiff"] 
    BusinessAddressArray = ["30 Brower Lane, Hillsborough, NJ 08844"] 
    BusinessNumberArray = ["(908) 281-9442"] 
    BusinessWebsiteArray = ["http://premieredancenj.com/"] 


    // Do any additional setup after loading the view. 
} 

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

// MARK: - Table view data source 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return BusinessNameArray.count 
} 


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell 

    let item = BusinessNameArray[indexPath.row] 

    cell.businessLabel.text = item 




    return cell 
} 
} 

BDTableViewCell:

import UIKit 

[![enter image description here][1]][1]class BDTableViewCell: UITableViewCell { 

@IBOutlet weak var businessLogo: UIImageView! 
@IBOutlet weak var businessLabel: UILabel! 
@IBOutlet weak var businessAddress: UILabel! 
@IBOutlet weak var businessPhone: UILabel! 
@IBOutlet weak var businessWebsite: UILabel! 

override func awakeFromNib() { 
    super.awakeFromNib() 
    // Initialization code 
} 

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 

    // Configure the view for the selected state 
} 

} 

ответ

8

С этой линией

var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell 

вы позволить компилятор знать что cell есть (только) a UITableViewCell, но у обычного UITableViewCell нет недвижимости под названием businessLabel. Когда вы меняете линию на

var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! BDTableViewCell 

код будет скомпилирован.

+0

И убедитесь, что у вас есть «BDTableViewCell», указанный в инспекторе атрибутов ячейки прототипа. – Adrian

+1

@AdrianB, если бы это было не так, он не смог бы подключить выходы в раскадровке. – Glorfindel