I've been stuck on this problem for a couple of days and I'm not why my table view will never load correctly. At first my cell was returning nil but now the console states:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/JosephHaddad/Library/Developer/CoreSimulator/Devices/2884D7B1-26CD-45F7-A044-9106962AE093/data/Containers/Bundle/Application/005E1198-CFA5-429B-960B-2367296BB6AD/Test.app> (loaded)' with name 'AllBarCell''
Here is my Custom Cell Class:
import UIKit
import Foundation
class AllBarCell: UITableViewCell {
// MARK: Properties
@IBOutlet weak var primaryBarImage: UIImageView?
@IBOutlet weak var barName: UILabel?
@IBOutlet weak var happyHourImage: UIImageView?
@IBOutlet weak var entImage: UIImageView?
struct Static {
static var data = CellDataDisplayInformation()
}
// MARK: Methods
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
}
override func prepareForReuse() {
self.barName?.text = nil
super.prepareForReuse()
}
}
And my corresponding tabbed-table view controller:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableView.registerNib(UINib(nibName: "AllBarCell", bundle: nil), forCellReuseIdentifier: "AllBarCell")
.....
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)-> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("AllBarCell", forIndexPath: indexPath) as! AllBarCell
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0)) {
dispatch_async(dispatch_get_main_queue()) {
if let futureCell = tableView.cellForRowAtIndexPath(indexPath) as? AllBarCell {
let data = AllBarCell.Static.data
// Update Happy Hour Image
let currentHour = GetTime()
if data.happyStart[indexPath.row] != 999{
if currentHour.currentHour >= data.happyStart[indexPath.row] && currentHour.currentHour <= data.happyEnd[indexPath.row] {
var barImage = UIImage(named: "HH")
futureCell.happyHourImage?.image = barImage
}
}
// Update Entertainment Hour Image
if data.entStart[indexPath.row] != 999 {
if currentHour.currentHour >= data.entStart[indexPath.row] && currentHour.currentHour <= data.entEnd[indexPath.row] {
var barImage = UIImage(named: "Ent")
futureCell.entImage?.image = barImage
}
}
// Update Bar Names
if data.pictureArray[indexPath.row] != nil {
futureCell.primaryBarImage?.image = data.pictureArray[indexPath.row]
}
if data.namesArray[indexPath.row] != nil {
futureCell.barName?.text = data.namesArray[indexPath.row]
}
}
}
}
return cell
}
I can't seem to fully solve one problem without encountering another. Yes my custom table view cell is connected to my custom cell class and my view controller is also connected to the correct view.
My two problems in summary:
1) making sure my -cellForRowAtIndexPath doesn't return a nil cell
2) avoiding this error: "Could not load NIB in bundle...with name 'AllBarsCell' "
Did you set the cell reuse identifier on the storyboard? That's usually what trips me up.
It is possible that you renamed the custom cell class file outside XCode. I think the error says that it can't find a nib file named "AllBarCell" in your project. So double check the name of your class. Try to remove it from the project and re-add it and see what happens.
I had a similar issue, the syntax of the view controller and the custom cell class were ok, and everything was set up fine in the .xib file.
The solution was in the storyboard. You should place yourself on your customTableViewCell.xib, press the File Inspector icon, and in Target Memeberhsip set your project name option on
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.