在尝试配置原型单元以与几个阵列一起使用时,我遇到了一个奇怪的错误。我已经设置了一个由'BDTableViewController'控制的表视图控制器,并包含一个由'BDTableViewCell'类控制的原型单元。但是,Xcode抱怨
'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
}
}
答案 0 :(得分:8)
使用此行
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
您让编译器知道cell
是(仅)UITableViewCell
,但常规UITableViewCell
没有名为businessLabel
的属性。将行更改为
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! BDTableViewCell
代码将编译。