此类不符合密钥的键值编码要求 [英] this class is not key value coding-compliant for the key

查看:59
本文介绍了此类不符合密钥的键值编码要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对快速开发非常陌生,并且正在研究

I am very new to swift development and I am working on this section of an apple provided swift tutorial. I created an outlet for a label, image, and custom view that are nested in a Table Cell. When I run I get this error

2016-07-20 23:16:11.110 FoodTracker[8446:3016336] Unknown class MealTableViewCell in Interface Builder file. 2016-07-20 23:16:11.124 FoodTracker[8446:3016336] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key nameLabel.' * First throw call stack:

There are no duplicate outlets and I believe the cellIdentifier used in my Table View Controller is correct. My table cell

import UIKit

class MealTableViewCell: UITableViewCell {

//    MARK: Properties
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var photoImageView: UIImageView!
@IBOutlet weak var ratingControl: RatingControl!

override func awakeFromNib() {
    super.awakeFromNib()
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}}

My Table View Controller

import UIKit

class MealTableViewController: UITableViewController {
// MARK: Properties

var meals = [Meal]()

override func viewDidLoad() {
    super.viewDidLoad()
    loadSampleMeals()
}

func loadSampleMeals() {
    let photo1 = UIImage(named: "meal1")!
    let meal1 = Meal(name: "Caprese Salad", photo: photo1, rating: 4)!

    let photo2 = UIImage(named: "meal2")!
    let meal2 = Meal(name: "Chicken and Potatoes", photo: photo2, rating: 5)!

    let photo3 = UIImage(named: "meal3")!
    let meal3 = Meal(name: "Pasta with Meatballs", photo: photo3, rating: 3)!

    meals += [meal1, meal2, meal3]
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return meals.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // Table view cells are reused and should be dequeued using a cell identifier.
    let cellIdentifier = "MealTableViewCell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MealTableViewCell

    // Fetches the appropriate meal for the data source layout.
    let meal = meals[indexPath.row]

    cell.nameLabel.text = meal.name
    cell.photoImageView.image = meal.photo
    cell.ratingControl.rating = meal.rating

    return cell
}}

Thanks!

解决方案

Check for a broken outlet link in your storyboard file. Find your controller and control-click on the yellow circle above its nib to open the actions and outlets popover. You should see an outlet for nameLabel with a yellow warning sign. Either reconnect it to your controller's file or remove it if its a duplicate.

这篇关于此类不符合密钥的键值编码要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆