简体   繁体   English

主题 1:信号 SIGABRT 错误 (Swift 2)

[英]Thread 1: Signal SIGABRT Error (Swift 2)

I am creating a table app (from AppCoda's tutorial book) but the error Thread 1: signal SIGABRT appears when I run my program.我正在创建一个表格应用程序(来自 AppCoda 的教程书),但是当我运行我的程序时出现错误Thread 1: signal SIGABRT 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:这是我的 Main.storyboard:

点击这个链接 1 1

this class is not key value coding-compliant for the key locationLabel.此类不符合键 locationLabel 的键值编码。

This means that your outlet for locationLabel is not set.这意味着您的locationLabel出口未设置。 So your code is crashing because it is trying to access a variable (in this case an outlet) that is nil.所以你的代码崩溃了,因为它试图访问一个为零的变量(在这种情况下是一个插座)。

没有看到异常的开头,我最好的猜测是您没有在故事板中为您的单元格提供正确的reuseIdentifiers ,或者您没有将单元格设置为您的自定义类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM