作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在 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/
我目前正在 xcode 上使用 swift 构建一个 ios 应用程序,我不断收到错误 instance member 'name' cannot be used on type 'clothing_
我是一名优秀的程序员,十分优秀!