我对快速开发非常陌生,我正在研究 this section苹果提供了快速教程。我为嵌套在表格单元格中的标签、图像和自定义 View 创建了一个导出。当我运行时出现此错误
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:
没有重复的导出,我相信我的 TableView Controller 中使用的 cellIdentifier 是正确的。 我的表格单元格
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)
}}
我的 TableView 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
}}
谢谢!
最佳答案
检查 Storyboard文件中是否存在损坏的 socket 链接。找到您的 Controller 和control
- 单击其 Nib 上方的黄色圆圈以打开操作和导出弹出窗口。您应该会看到带有黄色警告标志的 nameLabel
导出。将其重新连接到 Controller 的文件,或者将其删除(如果重复)。
关于ios - 此类不符合键的键值编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38496504/