我一直在這個問題上停留了兩天,我不是爲什麼我的表格視圖永遠不會正確加載。起初,我的手機是返回nil但現在的控制檯狀態:無法在自定義表格視圖的Bundle中加載NIB Cell Class
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''
這裏是我的自定義單元格類:
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()
}
}
而我相應的標籤表視圖控制器:
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
}
我似乎無法完全解決一個問題而不會遇到另一個問題。是的,我的自定義表格視圖單元格連接到我的自定義單元格類,並且我的視圖控制器也連接到了正確的視圖。
我的兩個問題中總結:
1)確保我-cellForRowAtIndexPath不返回零細胞
2)避免這個錯誤:「在包無法加載NIB ...用名'AllBarsCell'「
是我的單元複用標識是否正確設置上的腳本中設置項目名稱選項。 –