gpt4 book ai didi

ios - 快速 xcode 错误 : "instance member ' name' cannot be used on type 'clothing_category'

转载 作者:行者123 更新时间:2023-11-29 00:56:32 25 4
gpt4 key购买 nike

我目前正在 xcode 上使用 swift 构建一个 ios 应用程序,我不断收到错误 instance member 'name' cannot be used on type 'clothing_category.'

我已经设置了一个 tableviewcell,我需要在 clothing_categories 数组中获取适当的 clothig_category。有错误的行是: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

}

我该如何解决这个问题?

最佳答案

好的,我知道你错在哪里了。命名约定实际上会阻止这种情况,但无论如何。您实际上是在访问该名称,就像它是一个静态属性一样,而实际上它是一个实例属性。做这样的事情会解决你的问题:

let category = clothing_categories[indexPath.row]
cell.nameclothing_category.text = category.name

关于ios - 快速 xcode 错误 : "instance member ' name' cannot be used on type 'clothing_category' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37575362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com