2015-10-26 7 views
2

Я создаю приложение таблицы (из учебника учебника AppCoda), но при запуске моей программы появляется ошибка Thread 1: signal SIGABRT. Область отладки говорит:Тема 1: Сигнал SIGABRT Ошибка (Swift 2)

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) 

Вот мой код:


Пользовательские 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 
} 

Пользовательские 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 
} 

} 

Все мои выходы подключены к правая метка/изображение. Я попытался подключить и отключить их, но это не сработало.

Вот мой Main.storyboard:

Click this link1

+0

Вы используете раскадровки? Если да, можем ли мы сделать снимок? –

+0

Как добавить картинку, если она не в сети, только на моем рабочем столе? @CharlesTruluck –

+0

Вы можете загрузить его в редакторе сообщений. Просто нажмите 'edit' в нижней части экрана, а затем выберите значок изображения. Затем вы можете перетащить его со своего рабочего стола в окно браузера. (если это то, что вы имеете в виду) –

ответ

2

Этот класс не является ключевым значением, совместимым с кодировкой для ключевого местоположенияLabel.

Это означает, что ваша розетка для locationLabel не установлена. Таким образом, ваш код сбой, потому что он пытается получить доступ к переменной (в данном случае к розетке), которая равна нулю.

+0

Это выглядит как правильный ответ. –

+0

Я видел это много раз в своём собственном коде :(Узнал, чтобы найти это довольно быстро! – Swinny89

+0

Это помогло! Спасибо @ Swinny89 –

0

Не видя начало исключения, моя догадка, что вы не даете клеткам надлежащего reuseIdentifiers в раскадровку, или что вы не установил ячейку в ваш пользовательский класс.

Смежные вопросы