我目前正在构建一个ios应用程序,使用的是快速的xcode,并且我一直得到错误的instance member 'name' cannot be used on type 'clothing_category.'。
我已经设置了一个tableviewcell,我需要在clothing_categories数组中获取适当的clothing_categories。出现错误的行是:cell.nameclothing_category.text = clothing_category.name
以下是完整的代码:
class clothing_category: NSObject {
let name: String!
init (name: String) {
self.name = name
}
}
class categoryTableViewController: UITableViewController {
// MARK: Properties
// Create an array to hold the clothing.
var clothing_categories = [clothing_category]()
override func viewDidLoad() {
super.viewDidLoad()
// Load sample data
loadSampleClothing_categories()
}
func loadSampleClothing_categories() {
clothing_categories.append(clothing_category(name:"Jackets"))
clothing_categories.append(clothing_category(name: "Accessories"))
clothing_categories.append(clothing_category(name: "Pants"))
clothing_categories.append(clothing_category(name: "Color"))
clothing_categories.append(clothing_category(name: "Tops"))
clothing_categories.append(clothing_category(name: "Dressing for an Occaision"))
// Load up the array when the view is loaded.
clothing_categories.append(clothing_category(name:"Jackets"))
clothing_categories.append(clothing_category(name: "Accessories"))
clothing_categories.append(clothing_category(name: "Pants"))
clothing_categories.append(clothing_category(name: "Color"))
clothing_categories.append(clothing_category(name: "Tops"))
clothing_categories.append(clothing_category(name: "Dressing for an Occaision"))
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return clothing_categories.count
}
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "categoriesTableViewCell"
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier", forIndexPath: indexPath) as! catgeoriesTableViewCell
//Fetches the appropriate clothing_catgeory for the data source layout.
_ = clothing_categories[indexPath.row]
**cell.nameclothing_category.text = clothing_category.name**
return cell
}我如何解决这个问题?
发布于 2016-06-01 17:42:18
好吧,我知道你哪里出了问题。命名约定实际上会阻止这一点,但无论如何。您实际上是在访问名称,就好像它是一个静态属性,而实际上它是一个实例属性。做这样的事情会解决你的问题:
let category = clothing_categories[indexPath.row]
cell.nameclothing_category.text = category.namehttps://stackoverflow.com/questions/37575362
复制相似问题