Reputation:
I am creating a table app (from AppCoda's tutorial book) but the error Thread 1: signal SIGABRT
appears when I run my program. The debug area says:
2015-10-26 14:47:34.827 FoodPin[4232:291494] Unknown class _TtC1q23RestaurantTableViewCell in Interface Builder file.
2015-10-26 14:47:34.855 FoodPin[4232:291494] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x7f8062ca81d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key locationLabel.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000104a8df65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010671fdeb objc_exception_throw + 48
2 CoreFoundation 0x0000000104a8dba9 -[NSException raise] + 9
3 Foundation 0x0000000104e55f5b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000105358c4b -[UIView(CALayerDelegate) setValue:forKey:] + 173
5 UIKit 0x0000000105648923 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001049ceb10 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x0000000105647306 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x00000001053e52a5 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 388
9 UIKit 0x00000001053e5677 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 71
10 FoodPin 0x00000001048a5d85 _TFC7FoodPin29RestaurantTableViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 197
11 FoodPin 0x00000001048a646f _TToFC7FoodPin29RestaurantTableViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
12 UIKit 0x00000001053f76b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
13 UIKit 0x00000001053f77c8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
14 UIKit 0x00000001053cd650 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187
15 UIKit 0x0000000105400595 -[UITableView _performWithCachedTraitCollection:] + 92
16 UIKit 0x00000001053e89ad -[UITableView layoutSubviews] + 218
17 UIKit 0x000000010535911c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
18 QuartzCore 0x000000010976036a -[CALayer layoutSublayers] + 146
19 QuartzCore 0x0000000109754bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x0000000109754a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x00000001097491d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
22 QuartzCore 0x00000001097769f0 _ZN2CA11Transaction6commitEv + 508
23 QuartzCore 0x0000000109777154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
24 CoreFoundation 0x00000001049b99d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x00000001049b9947 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x00000001049aeebc CFRunLoopRunSpecific + 524
27 UIKit 0x00000001052a398d -[UIApplication _run] + 402
28 UIKit 0x00000001052a8676 UIApplicationMain + 171
29 FoodPin 0x00000001048abb0d main + 109
30 libdyld.dylib 0x000000010723792d start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here's my code:
Custom View Controller:
import UIKit
class RestaurantTableViewController: UITableViewController {
var restaurantNames = ["Cafe Deadend", "Homei", "Teakha", "Cafe Loisl", "Petite Oyster", "For Kee Restaurant", "Po's Atelier", "Bourke Street Bakery", "Haigh's Chocolate", "Palomino Espresso", "Upstate", "Traif", "Graham Avenue Meats", "Waffle & Wolf", "Five Leaves", "Cafe Lore", "Confessional", "Barrafina", "Donostia", "Royal Oak", "Thai Cafe"]
var restaurantImages = ["cafedeadend.jpg", "homei.jpg", "teakha.jpg", "cafeloisl.jpg", "petiteoyster.jpg", "forkeerestaurant.jpg", "posatelier.jpg", "bourkestreetbakery.jpg", "haighschocolate.jpg", "palominoespresso.jpg", "upstate.jpg", "traif.jpg", "grahamavenuemeats.jpg", "wafflewolf.jpg", "fiveleaves.jpg", "cafelore.jpg", "confessional.jpg", "barrafina.jpg", "donostia.jpg", "royaloak.jpg", "thaicafe.jpg"]
var restaurantLocations = ["Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Hong Kong", "Sydney", "Sydney", "Sydney", "New York", "New York", "New York", "New York", "New York", "New York", "New York", "London", "London", "London", "London"]
var restaurantTypes = ["Coffee & Tea Shop", "Cafe", "Tea House", "Austrian / Casual Drink", "French" ,"Bakery", "Bakery", "Chocolate", "Cafe", "American / Seafood", "American", "American", "Breakfast & Brunch", "Coffee & Tea", "Coffee & Tea", "Latin American", "Spanish", "Spanish", "Spanish", "British", "Thai"]
override func viewDidLoad() {
super.viewDidLoad()
// 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 {
return restaurantNames.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! RestaurantTableViewCell
// Configure the cell...
cell.nameLabel.text = restaurantNames[indexPath.row]
cell.locationLabel.text = restaurantLocations[indexPath.row]
cell.typeLabel.text = restaurantTypes[indexPath.row]
cell.thumbnailImageView.image = UIImage(named: restaurantImages[indexPath.row])
return cell
}
Custom Cell:
import UIKit
class RestaurantTableViewCell: UITableViewCell {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var locationLabel: UILabel!
@IBOutlet var typeLabel: UILabel!
@IBOutlet var thumbnailImageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
All my outlets are connected to the right label/image. I tried connecting and disconnecting them, but that didn't work.
Here's my Main.storyboard:
Upvotes: 2
Views: 1689
Reputation: 7373
this class is not key value coding-compliant for the key locationLabel.
This means that your outlet for locationLabel
is not set. So your code is crashing because it is trying to access a variable (in this case an outlet) that is nil.
Upvotes: 2
Reputation: 5258
Without seeing the beginning of the exception, my best guess is that you didn't give your cells the proper reuseIdentifiers
in your storyboard, or that you didn't set the cell to your custom class.
Upvotes: 0