首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >swift错误:“无法在'clothing_category‘类型上使用实例成员'name’

swift错误:“无法在'clothing_category‘类型上使用实例成员'name’
EN

Stack Overflow用户
提问于 2016-06-01 17:37:40
回答 1查看 1.1K关注 0票数 0

我目前正在构建一个ios应用程序,使用的是快速的xcode,并且我一直得到错误的instance member 'name' cannot be used on type 'clothing_category.'

我已经设置了一个tableviewcell,我需要在clothing_categories数组中获取适当的clothing_categories。出现错误的行是:cell.nameclothing_category.text = clothing_category.name

以下是完整的代码:

代码语言:javascript
复制
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

    }

我如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-01 17:42:18

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

代码语言:javascript
复制
let category = clothing_categories[indexPath.row]
cell.nameclothing_category.text = category.name
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37575362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档